我试图在玩家生成时创建灯光,但是我遇到了多个问题
我尝试了许多格式和功能,但总是会得到其中一种
“尝试索引零值”
“ [head(和其他事物)]不是[humanoid(和其他事物)]的成员”
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)
答案 0 :(得分:1)
您正遇到与此人相同的问题:(attempt to index field 'LocalPlayer' (a nil value))
我假设您已经在某个地方的脚本中编写了此代码。 LocalPlayer
只能在LocalScript中访问。尝试从服务器脚本访问它会导致LocalPlayer为零。幸运的是,您根本不需要使用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)