Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this localScript cause errors?

local hulkc = game.Players.LocalPlayer.Character.BodyColors
hulkcolor.HeadColor = "Sea green"
wait(1)
hulkcolor.LeftArmColor = "Sea green"  
wait(1)
hulkcolor.RightArmColor =  "Sea green"  
wait(1)
hulkcolor.RightLegColor =  "Bright violet"  
wait(1)
hulkcolor.LeftLegColor =  "Bright violet"  
wait(1)
hulkcolor.TorsoColor =  "Sea green"  

it says BodyColors isnt a valid member of the model ?????

2 comments

0

o god the title but srsly tho this is having errors idk why

0

Put it in Script Form to make it easier to see

1 answer

✓ Accepted answer

#What's the problem?

  • Body Colors has a space in between
  • LocalScripts run before the server start, therefore the script runs before the character loads
  • Why would you be using a local script to change parts especially if other players will see it, if FE is on then the player's Body Colors will not be visible to other players

#What can I do? Locate Body Colors like so: Character["Body Color"] or use :FindFirstChild() or even better: :WaitForChild().

Character["Body Color"]
Character:FindFirstChild("Body Color")
Character:WaitForChild("Body Color")

You can also stop using LocalScripts all together, because in this situation, it'll be easier to use a server Script.


#What are the Differences between Server-Sided and Client-Sided ServerSided:

  • Runs after the server is loaded
  • Can affect only server-sided actions
  • Can affect other players ClientSided:
  • Runs as soon as possible
  • Only affects the Player
  • Only runs if inside of a Descendant of Player

#What's the Difference between the 3 ways of calling Objects through strings? ["Body Color"] is the same as calling something like so: Character.BodyColor. If it doesn't exist, the script will error and the script will stop itself there. :FindFirstChild() is the same but will return nil if it doesn't exist and will still run the rest of the code. :WaitForChild() is the same as above, but will Yield the script(even though it's technically a regular function) for 5 seconds and will return nil if the object doesn't exist for 5 seconds. Note it has a 2nd parameter than can change how long the function will yield.


#Final Product

game:GetService("Players").PlayerAdded:connect(function(plyr)
	plyr.CharcterAdded:connect(function(char)
		repeat wait() until char:FindFirstChild("Body Color") --This way we don't need to worry about the 5 second time limit because each computer is different.
		local hulkcolor = char:FindFirstChild("Body Color")
		hulkcolor.HeadColor = "Sea green"
		hulkcolor.LeftArmColor = "Sea green"
		hulkcolor.RightArmColor = "Sea green"
		hulkcolor.RightLegColor = "Bright violet"
		hulkcolor.LeftLegColor = "Bright violet"
		hulkcolor.TorsoColor = "Sea green"
	end)
end)


Hope it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.