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

How to give the player a pointlight?

My script that gives the player a point light works... but only about half of the time. I have no idea why this is happening and it is very frustrating please help. It is a normal script attached to a part on top of spawn.

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid")then
		local light = Instance.new('PointLight')
		light.Parent = Hit.Parent.Head
		light.Brightness = 1
	end
	end)

1 comment

0

Am I tripping?

1 answer

✓ Accepted answer

If it's on top of a spawn, I'm assuming you want it every single time they spawn. In that case, the CharacterAdded event would be your friend here. Your current code works well, and the only issue could be the lack of debounce in it. With the CharacterAdded event, no debounce is needed.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild('Head') -- wait until the head is there
		local light = Instance.new('PointLight')
		light.Brightness = 1 -- Better practice to set all properties before you parent it
		light.Parent = char.Head
	end)
end)

Ask any questions!

2 comments

0

It works great thank you! One question though: I want one player, the beast, to not have this light. It's a round based game so after "the beast" is chosen, how do I make them lose the light?

0

You'd need to add an if statement to check if they're the beast based on your requirements. It would go after line 2, and would return false if they're the beast

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