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

How can I change someones cash value to 0 after they die?

Been trying to put together a piece of code to do this as it sounds simple but I cant wrap my head around it.. any help?

local Humanoid = script.Parent.Humanoid 
function PwntX_X() 
local tag = Humanoid:findFirstChild("creator") 
if tag ~= nil then 
if tag.Value ~= nil then 
local Leaderstats = tag.Value:findFirstChild("leaderstats") 
if Leaderstats ~= nil then 
Leaderstats.Currency.Value = Leaderstats.Currency.Value + 0 --Change Currency to Your Money 
wait(0.1) 
script:remove() 
end 
end 
end 
end 
Humanoid.Died:connect(PwntX_X) 

local Humanoid = script.Parent.Humanoid 
function PwntX_X() 
local tag = Humanoid:findFirstChild("creator") 
if tag ~= nil then 
if tag.Value ~= nil then 
local Leaderstats = tag.Value:findFirstChild("leaderstats") 
if Leaderstats ~= nil then 
Leaderstats.XP.Value = Leaderstats.XP.Value + 0 --Change XP To your Experience Name
wait(0.1) 
script:remove() 
end 
end 
end 
end 
Humanoid.Died:connect(PwntX_X) 

3 comments

0

ahhh, so many deprecated stuff and lack of indents.......

0

Doing 400 = 400 + 0............ So efficient...

0

^Do not bash on this persons question and or code. He is obviously a beginner, yes, but that does not mean you have to correct him in the tone in which you are using.

1 answer

✓ Accepted answer

You have two connections, but only need one (and likewise only need one "PwntX_X" function). Further, you don't want to increase the amount of money/XP they have, but rather set it to 0. Thus, instead of doing Leaderstats.Currency.Value = Leaderstats.Currency.Value + 0, just do Leaderstats.Currency.Value = 0. I'm going to assume that you don't actually have/need that 'creator' tag in the humanoid and that the leaderstats is a child of the player. Do note ideally this code would be server-side (though this is clearly client-side). Improved script (still client-side):

local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
	local stats = game.Players.LocalPlayer:FindFirstChild("leaderstats")
	if stats then
		stats.Currency.Value = 0
		stats.XP.Value = 0
	end
	script:Destroy()
end)

2 comments

1

Remember that :Remove() is deprecated. Replace it with :Destroy()

0

@PyccknnXakep: thanks, fixed

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