-
What do you want to achieve? I want to break a loop once the player dies
-
What is the issue? Using Humanoid.Died hasn’t worked
-
What solutions have you tried so far? I have looked at a few posts but nothing has helped
I’m making a game similar to blade ball and I have come across this issue. I am making a loop for the ball to follow the player but I want to stop it whenever the player dies so I tried to use the break word on a Humanoid.Died function.
game.Players.PlayerAdded:Connect(function(Player)
local Ball = workspace.Ball
for _,v in pairs(workspace:GetChildren()) do
if v:IsA("Part") and v.Name == "PlayerDetecters" then
v:Destroy()
end
end
local Part = Instance.new("Part")
Part.Name = "PlayerDetecters"
Part.Parent = workspace
Part.Anchored = false
Part.CanCollide = false
Part.Size = Vector3.new(999999999999,999999999999,999999999999)
Part.CFrame = Ball.CFrame
local con
con = Part.Touched:Connect(function(hit)
local enemy = hit.Parent:FindFirstChild("Humanoid")
if not hit.Parent:FindFirstChild("Humanoid") then return end
if enemy then
con:Disconnect()
print(hit.Parent)
local Client = Player
local object = game.Workspace.Ball
local speed = 80
while true do
local playerPos = Client.Character.HumanoidRootPart.Position
local objectPos = object.Position
local direction = (playerPos - objectPos).Unit
local distance = (playerPos - objectPos).Magnitude
if distance > 1 then
object.CFrame = object.CFrame + direction * speed * math.min(distance, 1/60)
end
enemy.Died:Connect(function()
break
end)
wait()
end
end
end)
end)
Apparently loops can only be stopped inside the loop but how would I do it if I want to stop it once the player dies?
Edit: Sorry for my bad english, it is not my first language