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

How do I set a enable the Fire Object inside a Part, with a Click Detector?

I want to set a Part on fire by clicking on the Part with my mouse, please help me. Btw, I do have a ClickDetector inside the Part and the Fire object. This is my code.

local Part = script.Parent

function fireOn()
	Part.Fire.Enabled = true
end

Part.MouseClick.Clickdetector:Connect(fireOn)

2 answers

✓ Accepted answer

You forgot to put the event in the right place.

MouseClick is the event you are using. This needs to go right before ":connect" in order to work.

local Part = script.Parent

function fireOn()
	part.Fire.Enabled = true
end

Part.ClickDetector.MouseClick:connect(fireOn) --also, connect is a lower case "c". Please check all code for case-sensitive(upper or lower case) errors

Let me know if this still doesn't work, and I will get back to you and fix it. Mark as correct if this solved your problem. Shoot me any more questions you have.

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

0

Thank you for your help :)

0

@ReynaldoVictarion :(

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