【问题标题】:How do you create a light inside the player?如何在播放器内部创建灯光?
【发布时间】:2019-10-12 12:09:34
【问题描述】:

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

我尝试了许多格式和功能总是不断得到任何一种

“尝试索引零值”

"[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)

【问题讨论】:

    标签: roblox


    【解决方案1】:

    你遇到了和这个人一样的问题:(attempt to index field 'LocalPlayer' (a nil value))

    我假设你已经在某个地方的脚本中编写了这个。 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)
    

    【讨论】:

      猜你喜欢
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多