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

Can you help me understand whats wrong here?

Im trying to make matches that will light a fire. Ive created a local script in the tool to do that. For some reason when I click on the fire with my matches nothing is happening. The Firepit is a model named "Fire" and there is an invisible part named "FirePart" within that model. When i click on it I want it to light the FirePart within the Fire Model. Can you help me? Anyone?

Here is the code.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function onEquipped()
	print("Matches")
end
script.Parent.Equipped:connect(onEquipped)

function onActivate()
	if mouse.Target == game.Workspace.Fire then
		local f = Instance.new("Fire", mouse.Target.Fire.FirePart)
	end	
end
script.Parent.Activated:connect(onActivate)

1 answer

✓ Accepted answer

mouse.Target will be the part that you are hovering over.

A simpler onActivate function to light anything you click on on fire would be this:

function onActivate()
	Instance.new("Fire", mouse.Target)
end

If we want to limit it to parts in the "FirePit" model, we should probably check the .Parent of mouse.Target:

function onActivate()
	local target = mouse.Target
	if target and target.Parent == workspace.FirePit then
		-- target is a part in the FirePit model
		Instance.new("Fire", target)
	end
end

Now, we want to specifically add the fire only to that one part, so we just change the parent to be the FirePart:

function onActivate()
	local target = mouse.Target
	if target and target.Parent == workspace.FirePit then
		-- target is a part in the FirePit model
		Instance.new("Fire", workspace.FirePit.FirePart)
	end
end

Or, equivalently

function onActivate()
	local target = mouse.Target
	if target and target.Parent == workspace.FirePit then
		-- target is a part in the FirePit model
		Instance.new("Fire", target.Parent.FirePart)
	end
end

If you wanted to have more than one model that you can light on fire, then we might as well just check for things named "FirePart" in the same model:

function onActivate()
	local target = mouse.Target
	if target and target.Parent:FindFirstChild("FirePart") then
		Instance.new("Fire", target.Parent.FirePart)
	end
end

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