-- Local Script
local event = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)
local string = “Clicked”
local db = true
script.Parent.MouseButton1Click:Connect(function()
if db then db = false
event:FireServer(string, db)
else
-- ???
db = true
end
end)
-- Server Script
local event = game.ReplicatedStorage:WaitForChild(“RemoteEvent”)
event.OnServerEvent:Connect(function(plr, string, db)
if db then
print(string)
else
print(string)
end
end)
Because I want to anchor multiple parts inside a folder in the workspace by clicking a button. I used :GetChildren() but it just picks a random part inside the folder and not all of it. Tried using a loop but it’s still not working. No errors too
well first of all, you don’t need to send db (if you are using it for debounce) to the server
just use it on the client to make sure the button can not be spammed
-- Client Script
local db = true
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local buttonDelay = 5
script.Parent.MouseButton1Click:Connect(function()
if db then
db = false
event:FireServer("buttonClicked")
wait(buttonDelay)
db = true
end
end)
-- Server Script
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
event.OnServerEvent:Connect(function(plr, message)
if message == "buttonClicked" then
print(message)
--do your anchoring and unanchoring here
--for _, part in pairs(workspace.PartFolder:GetChildren()) do
-- part.Anchored = not part.Anchored
--end
end
end)