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

How would I script it so when a press mousebutton1 when holding a tool it turns a surface light on?

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!

1 comment

0

I'm not sure but you can make an "if" statement to see whether the player is holding the tool when you click the button then change the surface light's value

2 answers

✓ Accepted answer

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!

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