Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I prevent this script from running multiple times?

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)

6 comments

0

run a debounce until the part has left the part

0

also isnt this abt the bouncy thing?

0

are you not able to read? i literally just said i tried to use a debounce and it doesnt work.

0

Try maybe adding a FindFirstChild or WaitForChild to check if there is a BV, and if there is, set a debounce that prevents it to add anymore BV. If there isnt BV set the debounce to false so it can add BV.

0

@LoganboyInCO i am able to read relatively fluently, like a normal human. But I would appreciate if u could read the last few words of what i said(like a normal human) and take it into consideration instead of seeing a "debounce" in my sentence and straight up criticizing it(aka ask me wydm by "part has left the part")

0

also what do u intedn to do with this?

1 answer

✓ Accepted answer

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

4 comments

0

damn "give it a shot before u shoot it down"

0

Good, i did not know that Instance.new("CLASSNAME", parent) is deprecated lmao

0

Small little mistake on line 13, you forgot the () for :Destroy(), and it should only put the force into it once, but overall it works very well, accepted.

0

lol

This discussion is preserved as it was. New answers, comments, and votes are closed.