Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't the script in the gui work?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

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

Log in to vote
3
Answered by 8 years ago

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)
Ad
Log in to vote
1
Answered by
xPolarium 1388 Moderation Voter
8 years ago

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.

0
Same error? yoshi8080 445 — 8y
0
Oh, right. On line 8 of "local body"; BodyColors should have a space in between in both words. So "Body Colors" xPolarium 1388 — 8y
0
Well I did that, nothing happened, and no error is showing yoshi8080 445 — 8y
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. xPolarium 1388 — 8y
0
The error came back, also I dunno how to use loops very well. yoshi8080 445 — 8y

Answer this question