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

I'm new to lua and can't work out clickdetector, help please?

Asked by 7 years ago

Please understand I've only just started and can't find any help for this online. I'm essentially trying to make a campfire that you can click for it to turn on.

This is what I have tried: function lightFire(part) fire = Instance.new("Fire") fire.Parent = part end

Campfire = workspace.Campfire

Campfire.ClickDetector.MouseClick:connect (lightFire)

~~~~~~~ I'm assuming that the reason this doesn't work is due to me not specifying a location, although I can't find how to do that, any help?

1 answer

Log in to vote
0
Answered by 7 years ago

The parameter that is passed through MouseClick is the Player object in Players, so you wouldn't know that something inserting a fire in there. To fix this, we can use the Character property and a thing in the player. For example, we can do

 function lightFire(plr)
    if plr.Character then --is the player dead and the new character is about to be spawned?
        Instance.new('Fire', plr.Character.Head) --You should not use the second argument for Instance.new with a thing that has physics, as it will cause many physics calculations when setting the properties.
    end
end

for the function

Hope this helps!

0
Sorry, but how would I go about making the fire light on the campfire rather than my head? Thanks. JackMills 0 — 7y
0
Nvm, I was just being stupid, thanks, :P JackMills 0 — 7y
Ad

Answer this question