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

Script only works once, no error output?

Asked by 9 years ago

I have a local script that's in a tool, and when you click it, it's supposed to make your character change into one of the materials from an array, but it only works once and won't change anything afterwards. I've been changing things for half an hour and haven't come up with any ideas as to what's wrong with it.

char = game.Players.LocalPlayer.Character:GetChildren()
tool = script.Parent
materials = {"Grass","Wood","Neon"}
m = materials[math.random(#materials)]

tool.Equipped:connect(function(mouse)

    mouse.Button1Down:connect(function()
        for i,v in pairs(char) do
            if v:IsA("Part") then
                    v.Material = m
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
funyun 958 Moderation Voter
9 years ago
player = game.Players.LocalPlayer
repeat wait() until player.Character --Gotta wait for the character before you can use it.
char = player.Character:GetChildren()

tool = script.Parent
materials = {"Grass","Wood","Neon"}

tool.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        local m = materials[math.random(#materials)] --I put line 4 down here so it will be a random material every time the mouse is clicked.
        for i,v in pairs(char) do
            if v:IsA("Part") then
                v.Material = m
            end
        end
    end)
end)
1
Thanks, it worked. I feel like such a idiot .-. lol, one day i'll be better at this ghostblocks 74 — 9y
Ad

Answer this question