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

Why can't the script in the gui work?

I was making the person who clicked it, turn into a certain thing but the body colors and such won't change? local script

local player = game.Players.LocalPlayer.Character
local shirt = player:FindFirstChild("Shirt")
local pants = player:FindFirstChild("Pants")
local face = player.Head:FindFirstChild("face")
local tshirt = player:FindFirstChild("Shirt Graphic")
local mesh = player:FindFirstChild("CharacterMesh")
local hats = player:FindFirstChild("Hat")
local body = player:FindFirstChild("Body Colors")
function onClick()
body.HeadColor = BrickColor.new("Bright yellow")
body.TorsoColor = BrickColor.new("Bright blue")
body.LeftArmColor = BrickColor.new("Bright yellow")
body.RightArmColor = BrickColor.new("Bright yellow")
body.LeftLegColor = BrickColor.new("Bright green")
body.RightLegColor = BrickColor.new("Bright green")
shirt:remove()
pants:remove()
tshirt:remove()
mesh:remove()
hats:remove()
face.Texture = "http://www.roblox.com/asset/?id=155216144"
end
script.Parent.MouseButton1Down:connect(onClick)

Error: Players.Player.PlayerGui.ShopGUI.GearFrame.Frame.ImageButton.LocalScript:10: attempt to index upvalue 'body' (a nil value)

2 answers

✓ Accepted answer

I'm not entirely sure why your script isn't working, but replace the script you've got with a normal script (not local) because otherwise only the player will see the character change. Use this code for the script:

char = script.Parent.Parent.Parent.Parent.Parent.Parent.Character

script.Parent.MouseButton1Down:connect(function()
	for i,v in pairs(char:GetChildren()) do
		if v:IsA("BodyColors") then
			v.HeadColor = BrickColor.new("Bright yellow")
			v.TorsoColor = BrickColor.new("Bright blue")
			v.LeftArmColor = BrickColor.new("Bright yellow")
			v.RightArmColor = BrickColor.new("Bright yellow")
			v.LeftLegColor = BrickColor.new("Bright green")
			v.RightLegColor = BrickColor.new("Bright green")
		elseif v:IsA("Hat") or v:IsA("CharacterMesh") or v:IsA("ShirtGraphic") or v:IsA("Shirt") or v:IsA("Pants") then
			v:remove()
		elseif v.Name == "Torso" and v:FindFirstChild("roblox") ~= nil then
			v.roblox:remove()
		elseif v.Name == "Head" then
			v.face.Texture = "http://www.roblox.com/asset?id=155216144"
		end
	end
end)

When setting a Color to properties, such as a Part's Color, you must use BrickColor.new(), so it can set it's color.

	body.HeadColor = BrickColor.new("Bright yellow")
	body.TorsoColor = BrickColor.new("Bright blue")
	body.LeftArmColor = BrickColor.new("Bright yellow")
	body.RightArmColor = BrickColor.new("Bright yellow")
	body.LeftLegColor = BrickColor.new("Bright green")
	body.RightLegColor = BrickColor.new("Bright green")

By the way, there's a way more efficient way to remove Shirts, Pants, and even changing the colors by using a For loop.

5 comments

0

Same error?

0

Oh, right. On line 8 of "local body"; BodyColors should have a space in between in both words. So "Body Colors"

0

Well I did that, nothing happened, and no error is showing

0

That did fix the error though. Maybe change the :remove() to :Destroy(). If not then I really recommend in using a for loop for this.

0

The error came back, also I dunno how to use loops very well.

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