Hey,
So basically, I’m trying to make it award money when a person kills them, but when they reset, they can still kill them for money. Here is the code.
BountyDiedConnection = BountiedPlayer.Character.Humanoid.Died:connect(function()
local creator = BountiedPlayer.Character.Humanoid:FindFirstChild("creator")
if creator then
print(creator.Value)
local killer = creator.Value
killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + amount
Unbounty(killer,false)
BountyDiedConnection:Disconnect()
end
end)
However, when the character dies, it’s still trying to find its character from previously, which doesnt exist because he died.
I was wondering on how you could work around this?
Thanks.
Try making it redefine the creator variable every time to refresh it. A new character is made when the old one dies and the variable won’t auto-update, but will instead return to nil. You just need to redefine it when it is nil or when the function runs.
EDIT: I meant to redefine the BountiedPlayer variable instead of Creator
No it’s not the full script but the rest doesn’t really matter.
Also I tested it and it didn’t work.
It doesn’t detect the change in variable.
It detects that the variable has changed but,
The event doesn’t change itself, if you die twice it only prints it once, as it’s still trying to see if the character died.
I’m not too sure on what is going on, but you can try this. When they die, disconnect the event always. Then check for “creator” after disconnecting. Currently, you have the disconnect inside the if-end area which checks for “creator”.
Then, use Player.CharacterAdded to reinstate the connection.
I found a solution, basically I kind of did a recursive event, it disconnects on death and reconnects afterwards. Here’s how it works for any people who have the same type of problem in the future.
local function plrDied()
local creator = BountiedPlayer.Character.Humanoid:FindFirstChild("creator")
if creator then
print(creator.Value)
local killer = creator.Value
killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + amount
Unbounty(killer,false)
BountyDiedConnection:Disconnect()
else
BountyDiedConnection:Disconnect() -- Disconnect it so the event we fired isn't in use.
BountyDiedConnection = BountiedPlayer.CharacterAdded:wait().Humanoid.Died:connect(plrDied) - Reconnect it, now its recursive.
print("char added")
end
end
BountyDiedConnection = BountiedPlayer.Character.Humanoid.Died:connect(plrDied) -- Fire event when died