Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

1 comment

0

now how do I make this only work once for local player?

This discussion is preserved as it was. New answers, comments, and votes are closed.