Why is my Parts moving when they aren't supposed too?

Issue

Okay so my only issue is if the button is spammed, the bricks all go inside of each other. I am not entirely sure how I can prevent that from happening.
https://gyazo.com/69f3a586b887f36f4077dc732e79debd

--Made By MillerrIAm & VersionQ
-------------Variables------------
local Event = game.ReplicatedStorage.ControlEvents.RotateLightsEvent
local MovementModule = require(game.ServerScriptService["Module Scripts | Lighting"].MovementModule)
local Enabled = false
local Num = 360
LightTable = {}
------------Main Script------------
Event.OnServerEvent:Connect(function(plr,Lights,Activate)
	if Activate == true then
		Enabled = true
		if Enabled == true then
			for i = 1,#LightTable do
				if #LightTable == nil or #LightTable == 0 then return end
				table.remove(LightTable,i)
			end
			for i,v in ipairs (game.Workspace.VenueLights[Lights]:GetChildren()) do 
				table.insert(LightTable,v.CFrame)
			end
			for x,v in ipairs (game.Workspace.VenueLights[Lights]:GetChildren()) do
			spawn(function()
				repeat
					MovementModule.Tween(v,Vector3.new(v.Orientation.X,v.Orientation.Y + Num,-145),nil)
				wait(0.5)
				until Enabled == false
				if #LightTable == nil or #LightTable == 0 then return end
				for i,v in ipairs (game.Workspace.VenueLights[Lights]:GetChildren()) do 
					v.CFrame = LightTable[i]
				end
			end)
		end
	end
	elseif Activate == false then
		Enabled = false
	end
end)

Thank you for any help you can give me

Create a debounce to only fire once the action is finished.

When and Why?

1 Like

Could you please elaborate on where you believe that should go?

something like this…

--Made By MillerrIAm & VersionQ
-------------Variables------------
local Event = game.ReplicatedStorage.ControlEvents.RotateLightsEvent
local MovementModule = require(game.ServerScriptService["Module Scripts | Lighting"].MovementModule)
local Enabled = false
local Num = 360
LightTable = {}
------------Main Script------------

local debounce = false;

Event.OnServerEvent:Connect(function(plr,Lights,Activate)
    debounce = true;
    if debounce == false then
        if Activate == true then
            Enabled = true
            if Enabled == true then
                for i = 1,#LightTable do
                    if #LightTable == nil or #LightTable == 0 then return end
                    table.remove(LightTable,i)
                end
                for i,v in ipairs (game.Workspace.VenueLights[Lights]:GetChildren()) do 
                    table.insert(LightTable,v.CFrame)
                end
                for x,v in ipairs (game.Workspace.VenueLights[Lights]:GetChildren()) do
                spawn(function()
                    repeat
                        MovementModule.Tween(v,Vector3.new(v.Orientation.X,v.Orientation.Y + Num,-145),nil)
                    wait(0.5)
                    until Enabled == false
                    if #LightTable == nil or #LightTable == 0 then return end
                    for i,v in ipairs (game.Workspace.VenueLights[Lights]:GetChildren()) do 
                        v.CFrame = LightTable[i]
                    end

                    debounce= false;
                end)
            end
        end
        elseif Activate == false then
            Enabled = false
        end
    end
end)
1 Like