一个服务,可以允许在 Player 对象中的属性默认值被设置。当玩家进入服务器时,玩家对象的每个属性都设置为相应属性的当前值 StarterPlayer 。
此外,您可以将四个对象添加到此服务:
- 一个 StarterPlayerScripts 实例,其中每个玩家运行一次的脚本。
- 一个 StarterCharacterScripts 实例,每次重生点时向每个玩家的角色添加脚本。
- 一个名为 的实例,将用作每个玩家角色的默认机器人。
- 一个名为 的实例,将用作所有玩家的角色模型。
概要
属性
描述网站对自定义虚拟形象动画的权限级别。
设置角色在移动设备上击中障碍物时是否自动跳跃。
玩家默认摄像头允许在钉子中缩放的最大距离。
玩家默认摄像头的最小距离允许放大。
将默认镜头像头的模式更改为第一或第三人称。
决定了 Humanoid.JumpHeight 对于 Player.Character 的初始值。
决定了 Humanoid.JumpPower 对于 Player.Character 的初始值。
决定了 Humanoid.MaxSlopeAngle 对于 Player.Character 的初始值。
决定 Humanoid.UseJumpPower 对于 Player.Character 的初始状态。
决定了 Humanoid.WalkSpeed 对于 Player.Character 的初始值。
设置默认相机如何处理在相机和玩家之间的对象。
如果玩家正在使用电脑,让开发者覆盖每个玩家的默认摄像头模式。
如果玩家正在使用电脑,让开发者覆盖玩家的移动模式。
如果玩家正在使用移动设备,让开发者覆盖每个玩家的默认相机移动模式。
如果玩家使用触摸设备,让开发者覆盖玩家的移动模式。
决定是否默认启用玩家的鼠标锁定。
设置此玩家可以看到其他 Humanoid 生命条的距离。如果设置为 0,生命条将不会显示。
是否应该加载玩家角色的外观。
指示是否将生成到体验中的角色配备上层服装配件。
设置此玩家可以看到其他 Humanoid 名称的距离。
决定是否在加载虚拟形象时加载用户拥有的表情。
属性
AllowCustomAnimations
该属性描述了当前游戏的权限级别关于自定义虚拟形象 Animations 从网站。
因此,无法在游戏内更改此值。它只能通过在网站上游戏设置页面中更改游戏的权限级别来更改。
该属性不适用于游戏。
AutoJumpEnabled
该属性设置角色在移动设备上击中障碍物时是否自动跳跃。
该属性从 StarterPlayer 复制到 Player 当他们加入游戏时。在此之后。该属性的值复制到角色的 Humanoid.AutoJumpEnabled 属性中的 Humanoid 在生重生点时。换言之,使用这三个属性可以在每个角色、每个玩家和每场游戏的基础上设置自动跳转行为。
代码示例
This code sample is meant for a TextButton. It allows the player to toggle the auto-jumping behavior while on a mobile device.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- Update button text
if player.AutoJumpEnabled then
button.Text = "Auto-Jump is ON"
else
button.Text = "Auto-Jump is OFF"
end
-- Reflect the property in the player's character, if they have one
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- Toggle auto-jump
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- Update everything else
update()
end
button.Activated:Connect(onActivated)
update()
AvatarJointUpgrade
CameraMaxZoomDistance
此属性设置了相机可以从默认相机与角色之间的最大距离以学分。
该属性设置了加入游戏的每个玩家的默认值 Player.CameraMaxZoomDistance 。如果这个值设置为低于 StarterPlayer.CameraMinZoomDistance 的值,它将增加到相机的最小缩放距离。
代码示例
The example demonstrates how to set a player's camera minimum and maximum zoom distance.
In this example, we set the Player.CameraMinZoomDistance and Player.CameraMaxZoomDistance to set the min and max distance in studs a player's camera can be from their character.
Note that since the example attempts to set the CameraMinZoomDistance to be greater than the CameraMaxZoomDistance, the CameraMinZoomDistance value will be decreased and set to the value of the max zoom distance.
To change the default min and max zoom distance values for a player when they first enter the game, you can change the StarterClass.Player.CameraMinZoomDistance and StarterClass.Player.CameraMaxZoomDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 75
CameraMinZoomDistance
这个属性设置了相机可以从默认相机与角色之间的最小距离,以学分为单位。
该属性设置了加入游戏的每个玩家的默认值 Player.CameraMinZoomDistance 。如果这个值设置为高于 StarterPlayer.CameraMaxZoomDistance 的值,它将被减少为 CameraMaxZoomDistance。
代码示例
The example demonstrates how to set a player's camera minimum and maximum zoom distance.
In this example, we set the Player.CameraMinZoomDistance and Player.CameraMaxZoomDistance to set the min and max distance in studs a player's camera can be from their character.
Note that since the example attempts to set the CameraMinZoomDistance to be greater than the CameraMaxZoomDistance, the CameraMinZoomDistance value will be decreased and set to the value of the max zoom distance.
To change the default min and max zoom distance values for a player when they first enter the game, you can change the StarterClass.Player.CameraMinZoomDistance and StarterClass.Player.CameraMaxZoomDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 75
CameraMode
为游戏中的每个玩家设置默认值 Player.CameraMode。相机有两种模式:
第一人称
在第一人称模式下,玩家的相机全程缩放。除非具有可见的 GUI 与 GuiButton.Modal 属性设置为 true ,否则鼠标将被锁定,用户的相机将随着鼠标移动转为镜头。
第三人称
在第三人称模式(默认)下,角色可以在相镜头中看到。在 Roblox 上的第三人称模式中:
- 您可以单击右键并拖动以旋转相镜头,或使用屏幕右下角的箭头键。
- 当你移动鼠标时,你的相机不会更改(除非你将鼠标移至屏幕末端)。
- 当您按下任何箭头键时,用户的角色将面向相应的箭头键的方向。
- 您可以自由缩放。
代码示例
This example demonstrates how to change the character's CameraMode to first person using the LockFirstPerson value of the Enum.CameraMode enum.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMode = Enum.CameraMode.LockFirstPerson
CharacterJumpHeight
该属性决定了玩家的 的初始值。该属性的值默认为 7.2 格。
此属性仅在属性窗口中可见,如果 StarterPlayer.CharacterUseJumpPower 设置为 false,否则无关。
由于此属性仅适用于将来生成的角色,更改它不会更改任何现有的玩家角色。对此属性的更改只会在玩家重生时生效。
CharacterJumpPower
该属性决定了玩家的 的初始值。该属性的值默认为 50,当应用于玩家的 Humanoid 时,将受到 0 到 1000 之间的约束。
此属性仅在属性窗口中可见,如果 StarterPlayer.CharacterUseJumpPower 设置为 true,否则无关。
由于此属性仅适用于将来生成的角色,更改它不会更改任何现有的玩家角色。对此属性的更改只会在玩家重生时生效。
CharacterMaxSlopeAngle
该属性决定了玩家的 的初始值。默认为 89°,因此人形可以默认攀登任何他们想要的坡度。当应用于玩家的 Humanoid 时,将受到 0 和 89 之间的限制。
由于此属性仅适用于将来生成的角色,更改它不会更改任何现有的玩家角色。对此属性的更改只会在玩家重生时生效。
CharacterUseJumpPower
决定了玩家的 的初始值。切换它将更改哪个属性在属性窗口中可见:CharacterJumpHeight(false)或StarterPlayer.CharacterJumpPower(true)。默认为真。
由于此属性仅适用于将来生成的角色,更改它不会更改任何现有的玩家角色。对此属性的更改只会在玩家重生时生效。
CharacterWalkSpeed
该属性决定了玩家的 Player.Character 的初始值为 Humanoid.WalkSpeed 。该属性默认为 16。
由于此属性仅适用于将来生成的角色,更改它不会更改任何现有的玩家角色。对此属性的更改只会在玩家重生时生效。
ClassicDeath
DevCameraOcclusionMode
定义默认相机脚本如何处理相机和相机主题之间的对象。适用于所有玩家加入体验时,不能为个人玩家更改。
默认值为 Zoom (0)。请参阅 Enum.DevCameraOcclusionMode 获取可用模式列表。
DevComputerCameraMovementMode
此属性可让开发者在玩家使用电脑时覆盖玩家的相机模式。
这是玩家加入游戏的默认属性。它可以通过设置 Player.DevComputerCameraMode 对个人玩家进行更改。
如果设置为 UserChoice 那么玩家的相机移动模式将由玩家在游戏设置中设置的任何内容决定。否则,模式将根据此属性设置。
查看 Enum.DevComputerCameraMovementMode 以获取可用的不同摄像头模式。
该属性对不在计算机上的玩家没有影响。
代码示例
The example demonstrates how to set a player's camera movement mode for players on a computer.
In this example, we set the camera movement mode to Classic via the Enum.DevComputerCameraMovementMode enum. This means that the camera of players on touch enabled devices will track the player but will not automatically rotate if the player walks left or right.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Set the player's camera movement mode on computers to classic
player.DevComputerCameraMode = Enum.DevComputerCameraMovementMode.Classic
DevComputerMovementMode
此属性可让开发者在玩家使用电脑时覆盖玩家的移动模式。
这是玩家加入游戏的默认属性。它可以通过设置 Player.DevComputerMovementMode 对个人玩家进行更改。
如果设置为 UserChoice 那么玩家的移动模式将由玩家在游戏设置中设置的任何内容决定。否则,模式将根据此属性设置。
查看 Enum.DevComputerMovementMode 可用的不同移动模式。如果玩家在电脑上,让开发者覆盖玩家的移动模式。
该属性对不在计算机上的玩家没有影响。
代码示例
Demonstrates how to set the movement mode for players on computers using the Player.DevComputerMovementMode property.
local Players = game:GetService("Players")
local function onPlayerAdded(player: Player)
-- Set the player's movement mode on desktop devices to click-to-move
-- Once set, the player can right click in the game world and the character will move there.
player.DevComputerMovementMode = Enum.DevComputerMovementMode.ClickToMove
end
Players.PlayerAdded:Connect(onPlayerAdded)
DevTouchCameraMovementMode
此属性可让开发者在玩家使用触摸设备时覆盖玩家的相机模式。
这是玩家加入游戏的默认属性。它可以通过设置 Player.DevTouchCameraMode 对个人玩家进行更改。
如果设置为 UserChoice 那么玩家的相机移动模式将由玩家在游戏设置中设置的任何内容决定。否则,模式将根据此属性设置。
查看 Enum.DevTouchCameraMovementMode 以获取可用的不同摄像头模式。
该属性对移动设备上的玩家没有影响。
代码示例
The example demonstrates how to set a player's camera movement mode.
In this example, we set the camera movement mode to Classic via the Enum.DevTouchCameraMovementMode enum. This means that the camera of players on touch enabled devices will track the player but will not automatically rotate if the player walks left or right.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Set the player's camera movement mode on mobile devices to classic
player.DevTouchCameraMovementMode = Enum.DevTouchCameraMovementMode.Classic
DevTouchMovementMode
此属性可让开发者在玩家使用触摸设备时覆盖玩家的移动模式。
这是玩家加入游戏的默认属性。它可以通过设置 Player.DevTouchMovementMode 对个人玩家进行更改。
如果设置为 UserChoice 那么玩家的移动模式将由玩家在游戏设置中设置的任何内容决定。否则,模式将根据此属性设置。
查看 Enum.DevTouchMovementMode 可用的不同移动模式。如果玩家使用触摸设备,让开发者覆盖玩家的移动模式。
该属性对不触摸启用设备上的玩家没有影响。
代码示例
The example demonstrates how to set the movement mode for players on touch enabled devices.
In this example, we set the movement mode to Thumbstick via the Enum.DevTouchMovementMode enum. This means that players on touch enabled devices are able to move via a virtual thumbstick on their screen.
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
-- Set the player's movement mode on mobile devices to a dynamic thumbstick
player.DevTouchMovementMode = Enum.DevTouchMovementMode.DynamicThumbstick
end)
EnableDynamicHeads
EnableMouseLockOption
此属性决定是否默认启用玩家锁定鼠标。
鼠标锁定将锁定玩家的鼠标指针在屏幕中心。移动鼠标会旋转Camera和Player将相对于相镜头当前旋转移动。
该属性设置了值 Player.DevEnableMouseLock 。
请注意,与Shift-Lock相关的 API 正在被弃用,因此建议使用 UserInputService.MouseBehavior 来锁定鼠标。
代码示例
The example demonstrates how to enable and disabled whether a player can lock their mouse.
In this example, we set the use a while true loop to toggle the state of the DevEnabledMouseLock property between true and false every 5 seconds. While this example has little practical use, it demos how to change the property via a LocalScript.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
while true do
player.DevEnableMouseLock = not player.DevEnableMouseLock
task.wait(5)
end
HealthDisplayDistance
该属性设置了这名玩家可以看到其他 Humanoid 生命条的距离,以学分为单位。如果设置为 0,生命条不会显示。此属性默认设置为 100 格。
要在玩家加入游戏后更改显示距离,您可以设置 Player.HealthDisplayDistance 属性。
如果 Humanoid 生命值栏可见,您可以使用 Humanoid.DisplayDistanceType 设置显示类型。
代码示例
This example demonstrates how to hide other Humanoid's (Player and NPC) health bars and names.
This is done by setting the player's Player.HealthDisplayDistance and Player.NameDisplayDistance properties to 0.
If you would like to display health bars and names, you set the properties to a value greater than 0. For instance, setting the properties to 100 means that the player will see other player's health and names up to 100 studs away.
To modify the default values for players, you can change the values of the StarterClass.Player.HealthDisplayDistance and StarterClass.Player.NameDisplayDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.HealthDisplayDistance = 0
player.NameDisplayDistance = 0
LoadCharacterAppearance
该属性设置玩家角色的外观是否应加载。
将其设置为 false 会导致玩家没有衣服(包括帽子)、身体颜色、身体包或与玩家虚拟形象相关的其他任何东西。默认情况下,此属性设置为 true .
将其设置为 true 会导致玩家加载相应于玩家 Player.CharacterAppearanceId 的外观。
如果使用 Player:LoadCharacterWithHumanoidDescription() ,将 StarterPlayer.LoadCharacterAppearance 设置为 false,因为玩家的虚拟形象不需要作为装备角色的所有资产ID,所有资产ID都来自传入的 HumanoidDescription 。
代码示例
This example demonstrates how to disable loading a player's character appearance. Instead, the player loads as a grey model without any hats, shirts, pants, etc.
This is useful for games using custom clothing and accessories.
Note that if the character has already spawned, this change will not take affect until the player respawns or the Player:LoadCharacter() function is called.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CanLoadCharacterAppearance = false
LoadCharacterLayeredClothing
指示是否生成到体验中的角色将配备层次服装配件(尽管 Workspace.MeshPartHeadsAndAccessories 也需要在 Workspace 中启用)。
LuaCharacterController
NameDisplayDistance
设置此玩家可以看到其他 Humanoid 名称的距离。如果设置为 0,名称将被隐藏。此属性默认设置为 100 格。
要在玩家加入游戏后更改显示距离,您可以设置 Player.NameDisplayDistance 属性。
如果 Humanoid 名称可见,您可以使用 Humanoid.DisplayDistanceType 设置显示类型。
代码示例
This example demonstrates how to hide other Humanoid's (Player and NPC) health bars and names.
This is done by setting the player's Player.HealthDisplayDistance and Player.NameDisplayDistance properties to 0.
If you would like to display health bars and names, you set the properties to a value greater than 0. For instance, setting the properties to 100 means that the player will see other player's health and names up to 100 studs away.
To modify the default values for players, you can change the values of the StarterClass.Player.HealthDisplayDistance and StarterClass.Player.NameDisplayDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.HealthDisplayDistance = 0
player.NameDisplayDistance = 0