Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Nuzixa 4
3 years ago

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!

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 denbra37 34 — 3y

2 answers

Log in to vote
0
Answered by
Pupppy44 671 Moderation Voter
3 years ago
Edited 3 years ago

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

Ad
Log in to vote
0
Answered by
SirGamezy 186
3 years ago

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!

Answer this question