How would I script it so when you hold a tool, and press mousebutton1 it changes the surfaceLight (In the tool) on, and when you press mousebutton1 again it turns it off?
Thanks!
You could have a variable called Toggled. Here's an example:
local Toggled = false -- Here's the Toggled variable local Tool = script.Parent -- Assuming that the script is in the tool function Activated() -- Function to detect if a player clicks mousebutton1 if Toggled == true then -- If Toggled is equal to *true* print("Toggled is on!") -- Prints out else -- Using else to do something else if Toggled is not true/is false print("Toggled is off!") -- Prints out end -- Ends the if statement end -- Ends the function Tool.Activated:Connect(Activated) -- Activated event
Hope this helps
Perhaps you can create a variable called Toggled like Pupppy's example, but I have a different script in mind.
If the script's parent is the tool, and the light's parent is the handle, then create a Script with the following:
local Toggled = false local Light = script.Parent.Handle.SurfaceLight script.Parent.Equipped:Connect(mouse) mouse.Button1Down:Connect(function() if Toggled = false then Light.Enabled = true Toggled = true else Light.Enabled = false Toggled = false end end) end)
I hope this is helpful!