Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you help me understand whats wrong here?

Asked by 10 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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
Ad

Answer this question