📜  从角色中获取玩家的最佳方法? - Lua 代码示例

📅  最后修改于: 2022-03-11 14:54:54.893000             🧑  作者: Mango

代码示例1
-- Do it easy bro
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(Character)
        print(plr)
        print(Character)
    end)
end)

-- There is more events like part.Touched to get the player too
-- Notice now we get the player searching the name of it? Thats how you get it
local myPart = script.Parent -- This Script is in a part from the Workspace
myPart.Touched:Connect(function(hit) -- Player touches the thing 
    local character = hit.Parent
    local humanoid = char:FindFirstChild("Humanoid")
    local player = game.Players:FindFirstChild(char.Name)
    
    -- Prevent other stuff touching that part to trigger your code
    if humanoid then
      -- Kill Player MUAHAHA
    end
end)