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)
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)