So, I was trying to use collection service for making functional kill parts, however, I had a while loop in my code, which made it lag extremely badly. I was told not only that the while loop was useless, but that the script would function without it. I’ve seen tutorials in which they don’t include a while loop, and the kill parts in those work seamlessly. I really wanna know what I can do to make these “kill” parts functional. (It works with a while loop, but not without one)
-- Services --
local Collection_Service = game:GetService("CollectionService")
-- Core --
local Core = script.Parent:WaitForChild("Core")
local GR_Point = Core:WaitForChild("Respawn_Point")
function Reset(Humanoid_Root_Part, Respawn_Point)
Humanoid_Root_Part.CFrame = Respawn_Point.CFrame
end
for I,V in pairs(Collection_Service:GetTagged("Kill_Part")) do
V.Touched:Connect(function(Hit)
print(GR_Point.Value.CFrame)
if Hit.Parent:FindFirstChild("Humanoid") then
local Humanoid_Root_Part = Hit.Parent:FindFirstChild("HumanoidRootPart")
if Humanoid_Root_Part then
Reset(Humanoid_Root_Part, GR_Point.Value)
end
end
end)
end