一種服務,可以將 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 的值,它將被減少為相機最大縮放距離。
範例程式碼
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
此屬性決定了玩家的 Player.Character 的初始值 Humanoid.JumpHeight 。此屬性的值預設為 7.2 格。
此屬性只在屬性窗口中可見,如果 StarterPlayer.CharacterUseJumpPower 設為 false,否則無關。
因為此屬性只適用於未來生成的角色,因此更改它不會更改任何現有玩家角色。對此屬性的變更只會在玩家重生時生效。
CharacterJumpPower
此屬性決定了玩家的 Player.Character 的初始值 Humanoid.JumpPower 。此屬性的值預設為 50,當應用於玩家的 Humanoid 時,將受到 0 和 1000 之間的限制。
此屬性只在屬性窗口中可見,如果 StarterPlayer.CharacterUseJumpPower 設為 true,否則無關。
因為此屬性只適用於未來生成的角色,因此更改它不會更改任何現有玩家角色。對此屬性的變更只會在玩家重生時生效。
CharacterMaxSlopeAngle
此屬性決定了玩家的 Player.Character 的初始值 Humanoid.MaxSlopeAngle 。它預設為 89°,因此人形可以預設攀爬任何他們想要的坡度。當應用於玩家的 Humanoid 時,將受到 0 到 89 之間的限制。
因為此屬性只適用於未來生成的角色,因此更改它不會更改任何現有玩家角色。對此屬性的變更只會在玩家重生時生效。
CharacterUseJumpPower
決定玩家的 起始值。切換它將更改哪個屬性在屬性視窗中可見:CharacterJumpHeight(否)或StarterPlayer.CharacterJumpPower(是)。預設為真。
因為此屬性只適用於未來生成的角色,因此更改它不會更改任何現有玩家角色。對此屬性的變更只會在玩家重生時生效。
CharacterWalkSpeed
此屬性決定了玩家的 起始值。此屬性默認值為 16。
因為此屬性只適用於未來生成的角色,因此更改它不會更改任何現有玩家角色。對此屬性的變更只會在玩家重生時生效。
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 。
請注意,與換擋鎖相關的 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 設為假值,因為玩家的虛擬形象不需要所有資產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