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

My coin collect script won't work? PLEASE HELP SDFOJISJDOIFSDJ

Asked by 4 years ago

I'm trying to make a coin collect script. Any help?

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit:findFirstChild("Humanoid")
    if humanoid ~= nil then
        game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value + 1
        script.Parent.Transparency = 1
        script.Parent.CollectSound:Play()
        wait(script.Parent.CollectSound.TimeLength)
        script.Parent:Destroy()
    end
end)

1 answer

Log in to vote
1
Answered by 4 years ago

Easy fix, you just need to do, hit.Parent, instead of hit

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid ~= nil then
        game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value + 1
        script.Parent.Transparency = 1
        script.Parent.CollectSound:Play()
        wait(script.Parent.CollectSound.TimeLength)
        script.Parent:Destroy()
    end
end)
Ad

Answer this question