Ad
Still have questions? Join our Discord server and get real time help.
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
2 months 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 2 — 2mo

2 answers

Log in to vote
0
Answered by
Pupppy44 671 Moderation Voter
2 months ago
Edited 2 months 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 152
2 months 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