Ok so first let's tell the script what part is
local Part = script.Parent
You did that already in your script
Now let's create a function to be called when a player clicks the button.
In this function will will turn on the fire.
function fireOn()
Part.Fire.Enabled=true
end
The part that you got wrong was on line 7 when you did
Part.MouseClick.Clickdetector:Connect(fireOn)
MouseClick is an event inside ClickDetector
so we do
Part.ClickDetector.MouseClick:connect(fireOn)
If we put this all together we get
local Part = script.Parent
function fireOn()
Part.Fire.Enabled=true
end
Part.ClickDetector.MouseClick:connect(fireOn)
BONUS
Let add more to the script.
lets say that we want the fire to turn on someone clicks the button and it's off
and turn off when someone clicks the button and it's on.
To do this we will check to see if it's on or off Before we set it.
Will will use an If statement for this
If Part.Fire.Enabled==true then Part.Fire.Enabled=false
elseif Part.Fire.Enabled==false then Part.Fire.Enabled=true
end
Now let's insert this into our function.
local Part = script.Parent
function fireOn()
If Part.Fire.Enabled==true then Part.Fire.Enabled=false
elseif Part.Fire.Enabled==false then Part.Fire.Enabled=true
end
end
Part.ClickDetector.MouseClick:connect(fireOn)
Now we have a button that'll turn on and off depending on what the fire's stat is.
We can even connect the function and the event together so we don't need that last part of the script.
local Part = script.Parent
Part.ClickDetector.MouseClick:connect(function()
If Part.Fire.Enabled==true then Part.Fire.Enabled=false
elseif Part.Fire.Enabled==false then Part.Fire.Enabled=true
end
end)
Hope this helped :)
2 comments
Thank you for your help :)
@ReynaldoVictarion :(