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

Why doesnt this only work on studio but nothing else?

Asked by 8 years ago

I'm trying to make it so when you touch a gold coin you'll get 25 points/coins. But it only works on studio. Help me please, also give me tips with scripting things for studio and outside of studio.

children = game.Workspace.Coins:GetChildren()
while true do
    for _, child in ipairs(children) do
        if child.Name == "GoldCoin" then
            child.Touched:connect(function(Touched)
            local p = Touched.Parent:FindFirstChild("Humanoid")
            if p ~= nil then
            local player = game.Players:GetPlayerFromCharacter(Touched.Parent)
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 25
            Sound = script.CoinSound:Clone()
            Sound.Parent = child
            Sound:Play()
            game.Debris:AddItem(Sound, 7)
            child:remove()
            end         
            end)
        end
    end
    wait()
end

0
One note, never ever ever ever ever use :remove(), only ever :destroy() (Unless you want to be able to re-parent the instance). Remove does NOT delete the object from the game, just sets it's parent to nil. Muoshuu 580 — 8y
0
Destroy also set the Parent to nil but however the only real difference between destroy and remove is that destroy locks the Parent property while remove sets it to nil. UserOnly20Characters 890 — 8y

Answer this question