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

Is there a way to make players not collect cash when dead?

Asked by 3 years ago

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)

1 answer

Log in to vote
1
Answered by
M9F 94
3 years ago
Edited 3 years ago

I’m currently on my phone but this should be the correct answer, if not let me know!

local DONTTOUCH = true
local Cash = script.Parent

local function PlayerTouched(playerPart)
    if playerPart.Parent:FindFirstChild("Humanoid") then
        local playerChar = playerPart.Parent
        local player = game.Players:GetPlayerFromCharacter(playerChar)
        if playerChar.Humanoid.Health >= 0 then 
            if DONTTOUCH == true then
                DONTTOUCH = false
                player.leaderstats:WaitForChild("Cash").Value += 5
                Cash.Transparency = 1
                Cash["Pickup"..math.random(1,3)]:Play()
                wait(1)
                Cash:Destroy()
            end
        end
    end
end

Cash.Touched:Connect(PlayerTouched)

That should be the fix if not let me know and I’ll hop on the computer and fix it up properly. I might’ve misspelled some things since I’m on ios and if I did I apologize. I’ll be sending you a friends req. My main account is named M9F.

0
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? TheBuliderMC 84 — 3y
0
My bad I’ll fix that M9F 94 — 3y
0
I made some edits to the code above, it should work now! M9F 94 — 3y
Ad

Answer this question