Hello guys so for some reason i made a award script and my script is not giving money with my own made sword but with the roblox sword it give the player the money so if you could help here the code:
local Humanoid = script.Parent.Humanoid
function dead()
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.Cash.Value = leaderstats.Cash.Value +10
wait(0.1)
script:Remove()
end
end
end
end
Humanoid.Died:Connect(dead)
Try this assuming that leaderstats is in the player
local Humanoid = script.Parent.Humanoid
function dead()
local tag = Humanoid:FindFirstChild('creator')
if tag and tag.Value then
local leaderstats = game.Players[tag.Value]:FindFirstChild('leaderstats')
if leaderstats ~= nil then
leaderstats.Cash.Value = leaderstats.Cash.Value +10
wait(0.1)
script:Destroy()
end
end
end
Humanoid.Died:Connect(dead)
I think it’s because you removed the script before calling the function try this one
local Humanoid = script.Parent.Humanoid
function dead()
local tag = Humanoid:FindFirstChild('creator')
if tag ~= nil then
local leaderstats = tag.Value:FindFirstChild('leaderstats')
if leaderstats ~= nil then
leaderstats.Cash.Value = leaderstats.Cash.Value +10
end
end
end
Humanoid.Died:Connect(dead)
wait(0.1)
script:Destroy()
local Humanoid = script.Parent.Humanoid
local plr = game.Players.LocalPlayer
if not Humanoid or Humanoid.Health == 0 then
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 222
end
--maybe this
local Humanoid = script.Parent.Humanoid
function Death()
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.Cash.Value = Leaderstats.Cash.Value + 1
end
end
end
end
Humanoid.Died:Connect(Death)
As @anirudh851 mentioned before. Does your sword have a tag system?
The roblox default sword has a tag system where when a player is hit → it creates a objectValue called creator, sets its value to the player who hit the target and parents it to the targets humanoid.