So I made a script for a button that would change the color of an object, everything worked fine until I decided to store the code in a localscript instead of a serverscript, because I also wanted to use it with a RemoteEvent for a GUI.
This is the code:
local button = script.Parent
local wasItClick = nil
button:WaitForChild("ClickDetector").MouseClick:Connect(function()
if not wasItClick then
wasItClick = true
local fire = Instance.new("Fire")
fire.Color = workspace.TweenButton.Part.Color
fire.Parent = workspace.TweenButton.Part
wait(2)
wasItClick = false
end
end)
I tried modifying the code, but it didn't work, also I'm new to scripting so it would be helpful if somebody could point out the errors in my code

2 comments
Local script can only run on Player Gui,backpack,...etc You can't make local script run on Workspace
At least your "wasItClick" becomes false at the end, so your MouseClick function will never work after the first time: it checks if wasItClick == nil (not wasItClick), but it's false now, so the "if" condition isn't met.