Hello i have been working on a script that making a player to a sheriff then gives him weapon and stuff, it gives him also a function for when he dies he will drop his hat and when a player picks it then he will become the new sheriff is it a way so i can give the new sheriff the same function for when he die instead of just writing the code again for him, because the new sheriff will be also able to drop his hat when he die.
`local sheriff = Survivors[math.random(1, #Survivors)]
if sheriff ~= murder then
local sheriffvalue = Instance.new("BoolValue", sheriff.Character)
sheriffvalue.Name = "SheriffValue"
sheriff.PlayerGui.Role.Holder.RoleGui.RoleType.Text = "Sheriff"
sheriff.PlayerGui.Role.Holder.RoleGui.RoleType.TextColor3 = Color3.fromRGB(0,0,255)
sheriff.PlayerGui.Role.Enabled = true
sheriffWeapon(sheriff, murder)
--- sheriff died ---
sheriff.Character.Humanoid.Died:Connect(function()
local SheriffHat = game.ServerStorage.SheriffThings.SheriffHat:Clone()
SheriffHat.CFrame = sheriff.Character.PrimaryPart.CFrame + Vector3.new(0,0.1,0)
SheriffHat.Parent = workspace
--- new sheriff ---
SheriffHat.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= murder.Character and hit.Parent ~= sheriff.Character then
SheriffHat:Destroy()
sheriff = game.Players:GetPlayerFromCharacter(hit.Parent)
sheriffWeapon(sheriff, murder)
print("new one "..sheriff.Character.Name)
end
end
end)
end)
end`
the problem is when the new player gets the sheriff varible, the died function will not run on him.