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

Why does it not increase the value of Money in this script?

Asked by
mine248 40
9 years ago

So I had made a code, and I made a script, but it didn't increase the value. Any solutions?

Faulty code:


enabled = true script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and enabled and script.Parent.Useable == true then local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.Money.Value = player.leaderstats.Money.Value + 100 script.Parent.Useable.Value = false script.Parent.Parent.TQ1.Useable = true wait(1) enabled = true end end)

1 answer

Log in to vote
0
Answered by 9 years ago

I'm assuming it's to do with the fact that you're missing a .Value from lines 4 and 11 after Useable. The if/then block on line 4 will never be true because you are comparing script.Parent.Useable, an Instance, to true, a boolean, which will never be equal. Instead, you need to check for the value.

Your code with fixes:

enabled = true

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and enabled and script.Parent.Useable.Value == true then


        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        player.leaderstats.Money.Value = player.leaderstats.Money.Value + 100
        script.Parent.Useable.Value = false
        script.Parent.Parent.TQ1.Useable.Value = true
        wait(1)
        enabled = true
    end
end)

Ad

Answer this question