for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
am:FireServer(v)
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
damageevent1:FireServer(v, hasmark, sprintdebounce)
end
end
Into a consistent loop (optional, could be 0.1 second breaks) without breaking the game. Also, I would like the loop to stop after a few seconds if the if statement does not activate. I’ve tried "while true do"s, but given my level of scripting I may just be using them wrong.
while task.wait(1) do
for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
am:FireServer(v)
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
damageevent1:FireServer(v, hasmark, sprintdebounce)
end
end
end
while task.wait(1) do
for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
am:FireServer(v)
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
damageevent1:FireServer(v, hasmark, sprintdebounce)
end
end
break --stops the loop
end
Hey, this is still the solution, but I basically want the if statement to break the loop the INSTANT it is activated. I already tried putting a break like this:
while task.wait(1) do
for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
dashevent:FireServer(v)
break
end
end
break --stops the loop
end
for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
dashevent:FireServer(v)
break
end
end
if that “if” statement fullfils the requirements that for i,v in pairs loop will break
then after that happens while task.wait(1) do loop will also break because it waits until for i,v in pairs finishes
no but the loop takes one full second to actually AFFECT v. I want it so that when something is sensed, the Id statement activates. I’m assuming the “while task.wait(1) do” needs to go, because I don’t want the affects of the loop to come a second after it starts.