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

My treasure chest is having problem, how do I fix this?

Asked by 2 years ago

It is working corectly, but when other player touch it, it doesn't give money to other player.

Script:

local debouce = true

local moneySFX = script.Parent.Money
local moneyEmitter = script.Parent.ParticleEmitter
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if debouce then
            debouce = false
            moneySFX:Play()
            moneyEmitter.Enabled = true
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.Money.Value = player.leaderstats.Money.Value + 25
            wait(1)
            moneyEmitter.Enabled = false
        end
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

the debounce is the problem, you need to set it back to true

local debouce = true

local moneySFX = script.Parent.Money
local moneyEmitter = script.Parent.ParticleEmitter
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if debouce then
            debouce = false
            moneySFX:Play()
            moneyEmitter.Enabled = true
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.Money.Value = player.leaderstats.Money.Value + 25
            wait(1)
            moneyEmitter.Enabled = false
        debounce = true -- add this line so you can get cash again
        end
    end
end)
0
now how do I make this only work once for local player? ThiagoGamestar 11 — 2y
Ad

Answer this question