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

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

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

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!

2 comments

0

Sorry, but how would I go about making the fire light on the campfire rather than my head? Thanks.

0

Nvm, I was just being stupid, thanks, :P

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