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

How to give the player a pointlight?

Asked by 4 years ago

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)
0
Am I tripping? Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
4 years ago

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!

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? DevSpyChicken 8 — 4y
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 Shawnyg 4330 — 4y
Ad

Answer this question