如何在播放器内部创建灯光?

How do you create a light inside the player?

我试图在玩家重生时创建灯光,但我 运行 遇到了多个问题

我试过很多格式和功能,总是不断得到

"Attempt to index nil value"

"[head(and other things)] 不是 [humanoid(and other things)]"的成员

game.Players.PlayerAdded:Connect(function(playersdude)
    playersdude.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
        local light = Instance.new("PointLight")
        light.Parent = game.Players.LocalPlayer.HumanoidRootPart
    end)
end)

您 运行 遇到了与此人相同的问题:()

我假设您已经在某个地方的脚本中编写了它。 LocalPlayer只能在 LocalScript 中访问。尝试从服务器脚本访问它会导致 LocalPlayer 为 nil。幸运的是,您根本不需要使用 LocalPlayer!

您可以使用 CharacterAdded 连接中提供的 char 来查找玩家的头部。

game.Players.PlayerAdded:Connect(function(playersdude)
    playersdude.CharacterAdded:Connect(function(char)
        -- search through the character model to find the head
        local head = char:FindFirstChild("Head", true)

        -- add a light bright enough to make them glow like the mid-morning sun
        local light = Instance.new("PointLight", head)
        light.Brightness = 100
    end)
end)