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

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

Asked by 6 years ago
Edited 6 years ago

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) 
0
ahhh, so many deprecated stuff and lack of indents....... hiimgoodpack 2009 — 6y
0
Doing 400 = 400 + 0............ So efficient... hiimgoodpack 2009 — 6y
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. PyccknnXakep 1225 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
1
Remember that :Remove() is deprecated. Replace it with :Destroy() PyccknnXakep 1225 — 6y
0
@PyccknnXakep: thanks, fixed chess123mate 5873 — 6y
Ad

Answer this question