How do I prevent this script from running multiple times (effects it has)
It makes tons of BodyVelocity
in the same part, I also need to destroy the body velocity after x amount of second but dont know exactly how, can anyone fix it making tons of Bodyvelocity
in the same part? Thanks.
I also tried to use debounce but that just slowed down the rate which makes more BodyVelocity
in the same part.
script.Parent.Touched:Connect(function(touched) if touched.Name == "EF2" or touched.Name == "EF1" then local force = Instance.new("BodyPosition",touched) local noforce = script.Parent.Parent.destroy local noforceclone = force:Clone().Parent == force force.MaxForce = Vector3.new(4000,4000,4000) force.Parent = touched force.Position = script.Parent.Parent.debripos.Position end end)
I've been trying to use the disconnect function somewhere in the script, but I can't find out how to make that work. The only thing I can think of is not letting the script run unless :FindFirstChild("Force") comes back as nil. This would make your script look like this:
script.Parent.Touched:Connect(function(touched) local check = touched:FindFirstChild("Force") if touched.Name == "EF2" or touched.Name == "EF1" and not check then local force = Instance.new("BodyPosition") force.Parent = touched -- took this out of the parentheses, that method of parenting is deprecated. local noforce = script.Parent.Parent.destroy local noforceclone = force:Clone().Parent == force force.MaxForce = Vector3.new(4000,4000,4000) force.Parent = touched force.Position = script.Parent.Parent.debripos.Position force.Name = "Force" wait(x) force:Destroy end end)
I know this is almost the same as a debounce, but give it a shot before you shoot it down.
-Cmgtotalyawesome