I run a function so whenever the player is added it runs, But when they die and respawn the function does not run again unless I die. is there any way to have it run and get the player over and over again regardless of if he dies or not?
local NPC = {}
function NPC.PlayerAttack(Char, Self)
local Players = game.Players
local Fire = require(game.ServerScriptService.Shard)
local Debounce = false
local HumanoidRoot = Char:FindFirstChild("HumanoidRootPart")
local Mag = (Self.HumanoidRootPart.Position - HumanoidRoot.Position).Magnitude
if Mag < 15 and not Debounce then
Debounce = true
Fire.Make(Self.HumanoidRootPart)
wait(2)
Debounce = false
else
Self.Humanoid:MoveTo(HumanoidRoot.Position)
end
end
return NPC
Full first script
local Players = game.Players
local Store = script.Parent:Clone()
local NPC = require(game.ServerScriptService.NPC)
local Debounce = false
local Char
print("Actiaved")
local function Look(Character)
print("Looking")
while wait() do
if not Debounce then
Debounce = true
NPC.PlayerAttack(Character, script.Parent)
wait(1)
Debounce = false
end
end
end
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
Look(Char)
end)
end)