So I have this code:
Serverscript in tool:
local Player = nil
local hum = nil
script.Parent:WaitForChild("Event").OnServerEvent:Connect(function(player, mouse)
print(mouse)
print(player.Name)
Player = player
wait()
if mouse then
print(mouse)
local target = mouse
if target.Parent:FindFirstChild("Humanoid") or target.Parent.Parent:FindFirstChild("Humanoid") then
if target.Parent:FindFirstChild("Humanoid") then
hum = target.Parent.Humanoid
else
hum = target.Parent.Parent.Humanoid
end
print(hum.Parent.Name)
wait()
local mag = (hum.Parent.Torso.Position - Player.Character.Torso.Position).magnitude
if hum.Health == 0 and mag <= 5 then
if not hum.Parent:FindFirstChild("CPR") then
wait()
local cprval = Instance.new("NumberValue")
cprval.Parent = hum.Parent
cprval.Name = "CPR"
cprval.Value = 0
local cprdoing = Instance.new("BoolValue")
cprdoing.Parent = hum.Parent
cprdoing.Name = "DoingCPR"
docpr(hum.Parent)
elseif hum.Parent:FindFirstChild("CPR").Value ~= 3 then
docpr(hum.Parent)
else
game.ReplicatedStorage.Events.Notification:FireClient(player, "Failed CPR", "Try and use the AED.", 5)
end
else
game.ReplicatedStorage.Events.Notification:FireClient(player, "Failed CPR", "This player is not dead or to far away.", 5)
end
end
end
end)
LocalScript in tool:
script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
local target = mouse.Target
if not target then return else
script.Parent.Event:FireServer(mouse.Target)
end
end)
end)
First 3 times it works, but if the player dies again nothign get's printed on the ServerScript side when i try the cpr/click. Does someone have a solution?
