generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: This is strange, any help?

Previous Thread :: Next Thread 
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 03:46 AM
local Hats = {["Necklace"] = true, ["Swords"] = true, ["Protector"] = true, ["Fedora"] = true, ["Shades"] = true}

local Selected = {1,2,3} --Hats A, B, and C

if body then
print "3"
for i=1, #Hats do
print "loop"
print (i)
print (Selected[i])
if Selected[i] == i then
print "4"

It prints 1, 2, and 3. Then it doesn't do anything else. there's more code, but this is all that matters, considering the values being used and the output...

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 03:47 AM
The number of hats prints as 0...

Odd...

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 03:59 AM
Stranger issue...

Once I parent a mesh to a hat's "handle", the mesh never pops up, and the textures don't show up at all, but the mesh does...

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 04:15 AM
No textures in solo mode, meshes are nonexistent, and in online mode, no errors and it does not run... odd...

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 06:01 AM
I don't understand my prior issues, such as why they were happening or what the cause was, but I found another way, which is arguably easier in terms of editing the script, but might be a little more complex on the outside...

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
cart6157 is not online. cart6157
Joined: 28 Feb 2009
Total Posts: 2194
23 Feb 2013 06:25 AM
What are you trying to do? Maybe you need to write it different.
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
23 Feb 2013 06:51 AM
I know what's happening.

The problem you are encountering here is the fact that you are using # to identify the number of indexes in a table.

However, # only checks on numbers. Basically you could write it as this (note: not valid lua code, but to give you an idea)

function #(table) --not correct, you cannot use # as function name and table is a library, I wouldnt use that as variable ( but this is for the idea)
local got = 0
while table[got + 1] do
got = got + 1
end
return got
end

This would only check the number indexes.

To find all normal indexes including strings, you could do:

function Count(t) --t is table
local output = 0
for i,v in pairs(t) do
output = output + 1
end
return output
end

That returns all numbers of indexes.

What you need however is to use pairs(table)

pairs(table) returns two things: the index and the value. Example:

local table = {"Hello",
["Mickey Mouse"] = true}

for index, value in pairs(table) dp
print(index, value)
end

That would print:

1 Hello
Mickey Mouse true

You can use that for your script (in fact you need it).
Report Abuse
12packkid is not online. 12packkid
Joined: 24 Jun 2011
Total Posts: 1418
23 Feb 2013 06:56 AM
Easier way to say: The '#' operator gets the amount of children, or variables in a table.

Example:

x = {1,2,3,4}
print(#x) -- It would print 4.
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
23 Feb 2013 06:58 AM
^Yes that's right, but that's not gonna fix his script.

And you forgot to say that it only counts number indices.
Report Abuse
Mathfreak231 is not online. Mathfreak231
Joined: 21 Jun 2010
Total Posts: 5311
23 Feb 2013 08:05 AM
no

print(#{1, 2, "hello", 6, "boo"})

prints 5
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
23 Feb 2013 08:09 AM
Christ, learn about indexes.

local TEST = {1,2,3,nil,5, Hello = true, ["Mickey Mouse"] = "good"}
print(#TEST)

--5 IS NOT 7.
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 08:40 AM
Alright, I'm used to just using # to find how many indexes are in a table.

It didn't work, so I tried something else.

Anyway, I am having a stranger problem right now.


function Entered(player)
if player then
if isAdmin[player.Name] then
player.CharacterAdded:connect(function(character)
if character then
local plr = game.Players:GetPlayerFromCharacter(character)
Entered(plr)
end end)
local body = player.Character
if body then
RemoveHats(body)

--[[]]

function RemoveHats(body)
local checks = body:GetChildren()
for i=1, #checks do
if checks[i].ClassName == "Hat" then
checks[i]:Destroy()
print "Hat Destroyed"
end end end

game.Players.PlayerAdded:connect(Entered)

It's strange... I knew I needed to remove my current hats before adding new hats. I thought it would be simple, so I quickly wrote this. It's actually slightly different, but this does the same thing as the new form. (if checks[i]:IsA("Hat") then).

This has worked... it worked when the player was added, and the Entered function was called. Before I added the hat remover part, this script would successfully give me the 3 hats I choose when I entered the game and when I respawned, with no differences. Now, when I enter the game, it will remove the hat I have on, but when I respawn, it will not, and just give me the new hats.

I did put in prints, and the script will check if each object in the table is a hat or not, but will never return true. I've double checked that I am giving it a character model as an argument, added a wait to just see if it's loading the character too late, etc... (Adding waits will actually change the behavior in unexpected ways).

I type a lot, but it's strange... I'm sure there needs to be something obvious, and I didn't sleep last night... I think this is the only part of the script that matters. There are no output errors, which makes me believe it is a logic issue.

"if checks[i].ClassName == "Hat" then" --There seems to be a problem with this line, because if I put a print before and after this, say 3 before and 4 afterwards... Then I put a print for 1 before calling the RemoveHats function, and a print 2 after calling this same function...

The output would look like:

1
3
3
3
3
(more 3s)
2

Skipping the 4 as you can see, and won't remove my hats. But it works the first time. (So how can it be a logic error, when the conditions "should" be the same, but the results are different?) I'm puzzled... :/

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
23 Feb 2013 08:45 AM
Thanks, Jobro1, for the help. I did eventually just resort to changing the loop slightly to achieve the same effect, but would require more editing later. (Slightly more, nothing that's too complex or hard to handle).

The main issue resulted from the strange missing meshes and textures, but I decided to create these before the server initialized instead, and just create a clone of them and a new hat.

But, now I'm experiencing another weird issue. I am hoping it's a simple mistake, but I've asked a couple friends who are experienced Lua scripters, and they can't find anything wrong with it.

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
24 Feb 2013 08:50 AM
Still looking for help...

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
25 Feb 2013 03:39 AM
:/

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
25 Feb 2013 08:22 AM
*Sigh*

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
26 Feb 2013 11:45 AM
Why not use a local script in starter pack? You are sure that always runs :)
Report Abuse
SunTzu16 is not online. SunTzu16
Joined: 10 Jul 2012
Total Posts: 999
28 Feb 2013 04:18 PM
It's not having issues running, but I'll look into it.

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image