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

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

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

✓ Accepted answer

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.

3 comments

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?

0

My bad I’ll fix that

0

I made some edits to the code above, it should work now!

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