Making a thing where money drops when player dies. Problem is that the cash can be picked up by dead players. Is there a way to fix that, or even add a small cooldown when it spawns so it can't be instantly collected?
local DONTTOUCH = true
local Cash = script.Parent
local function PlayerTouched(player)
if DONTTOUCH == true then
DONTTOUCH = false
local humanoid = player.Parent:FindFirstChild('Humanoid')
local player = game.Players:FindFirstChild(player.Parent.Name)
if humanoid and player then
player.leaderstats:WaitForChild("Cash").Value += 5
Cash.Transparency = 1
Cash["Pickup"..math.random(1,3)]:Play()
wait(1)
Cash:Destroy()
end
end
end
Cash.Touched:Connect(PlayerTouched)

3 comments
Doesn't seem to be working. Error: leaderstats is not a valid member of Model "Workspace.TheBuliderMC". Shouldn't the error not pop up if the player dies?
My bad I’ll fix that
I made some edits to the code above, it should work now!