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

I tried to make a code that would create fire only if there wasn't one already?

This is the code that I made. Please tell me why it isn't working

function lightOnFire(part)	

	water = part:FindFirstChild("Fire")

	if not water then

	fire = Instance.new("Fire")

	fire.Parent = part
end
 
firePart = game.Workspace.FirePart

firePart.Touched:connect(lightOnFire)

1 answer

First of all, you are missing an end.

function lightOnFire(part)  

    if not water then

    end

end

There is no need to declare water, unless you are going to use it again later. You also don't have to declare fire, because you can parent it in instance.new. "workspace" is short for game.Workspace. You might want to use waitforchild to make sure your script always works both online and in studio. Finally, unless you want to use firePart or call that function again somewhere, there is a much simpler way to create this connection.

workspace:WaitForChild("FirePart").Touched:Connect(function(part)  
    if not part:FindFirstChild("Fire") then
        Instance.new("Fire", part)
    end
end)

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