Player
The 'Player' class in Highrise represents each individual participant in the game. It is a crucial element, acting as the bridge between the player's real-world actions and their in-game avatar's behaviors.
Provides access to the player's user information, character, moderation status, and events.
Access players via:
client.localPlayer- The local player on clientscene.players- All players in current scene (recommended)game.players- All players across all scenes
Example usage:
Properties
Event fired when the player's character object changes. Triggered when player.character is set to a new GameObject, NOT when the character's outfit changes.
Use this to detect when a player spawns or respawns.
Event Parameters: Player: the player whose character object changed New Character: the new character GameObject (can be nil) Old Character: the previous character GameObject (can be nil)
--!Type(Server)
function self:ServerStart()
scene.PlayerJoined:Connect(function(scene, player)
-- Character may not exist yet, wait for it
player.CharacterChanged:Connect(function(player, newChar, oldChar)
if newChar ~= nil then
print(player.name .. " character spawned!")
-- Setup character on spawn
newChar.transform.position = Vector3.new(0, 5, 0)
-- Add custom components
local healthComponent = newChar:GetComponent(HealthSystem)
if healthComponent then
healthComponent:SetMaxHealth(100)
end
end
if oldChar ~= nil then
print(player.name .. " character destroyed")
end
end)
end)
end
Event fired when the player's pet changes, either by changing to a different pet or changing the accessories equipped to the current pet. Event Parameters: Player: the player whose pet changed Outfit: the new outfit of the pet
Event fired when the player starts talking in a voice channel. Event Parameters: Player: the player who started speaking
Event fired when the player stops talking in a voice channel. Event Parameters: Player: the player who stopped speaking
The chat channel the player is currently active in.
The character GameObject that represents this player in the world. Use this to manipulate the player's visual representation, position, and movement.
NOTE: Only server scripts can set the character. Character can be nil if the player hasn't spawned yet.
--!Type(Server)
-- Access player character
if player.character ~= nil then
local pos = player.character.transform.position
print(player.name .. " is at: " .. tostring(pos))
-- Teleport player
player.character.transform.position = Vector3.new(0, 10, 0)
end
-- Wait for character to spawn
player.CharacterChanged:Connect(function(player, newChar, oldChar)
if newChar ~= nil then
print(player.name .. " character spawned!")
end
end)
The transform where chat bubbles are spawned. It can be used to position objects above a character's head.
Returns true if the player has a pet, false otherwise.
An identifier for the player's current connection to the world. If the player leaves and joins the same world instance or a different one this value will change. For a unique identifier for the player that will not change, use player.user.id.
True if the player has verified their age as 18 or older. Use this to restrict access to age-gated content or features.
This is the same as player.user.isAgeVerifiedAbove18 for convenience.
--!Type(Server)
-- Restrict access to mature content
function AllowAccess(player)
if not player.isAgeVerifiedAbove18 then
print("Age verification required")
return false
end
return true
end
-- Age-gated scene
local matureScene = server.LoadScene("MatureContent", true)
server.PlayerConnected:Connect(function(player)
if player.isAgeVerifiedAbove18 then
server.MovePlayerToScene(player, matureScene)
end
end)
True if the player has left the world and this Player object is no longer valid.
IMPORTANT: If the player rejoins, a NEW Player object will be created. This value will never change back to false once it becomes true.
Use this instead of comparing to nil when checking if a Player object is valid.
--!Type(Server)
local playerData = {}
function self:ServerStart()
server.PlayerConnected:Connect(function(player)
playerData[player.user.id] = player
end)
server.PlayerDisconnected:Connect(function(player)
-- Clean up player data
playerData[player.user.id] = nil
end)
end
function self:ServerUpdate()
-- Check if stored player is still valid
for userId, player in pairs(playerData) do
if player.isDestroyed then
print("Player " .. userId .. " has left")
playerData[userId] = nil
end
end
end
True if the player has disconnected from the server (network disconnection). Similar to IsDestroyed but specifically for network disconnections.
if player.isDisconnected then
print(player.name .. " has disconnected")
end
Whether this player is the local player on the client.
True if this player has moderation rights in this world instance.
For owned rooms: True for the room owner and any moderators they've added For public worlds: True for the world creator and any world members
Use this to grant special permissions or commands to moderators.
--!Type(Server)
function self:ServerStart()
server.PlayerConnected:Connect(function(player)
if player.isModerator then
print(player.name .. " is a moderator!")
-- Grant moderator perks
local transaction = InventoryTransaction.new()
transaction:GivePlayer(player, "mod_badge", 1)
Inventory.CommitTransaction(transaction)
end
end)
end
-- Restrict commands to moderators
function HandleCommand(player, command)
if command == "/kick" and player.isModerator then
-- Process kick command
else
print("Only moderators can use this command")
end
end
Returns whether the player is currently speaking in a voice channel.
Whether this player has an active subscription to Highrise+.
The name of the player. This can be used to identify the player in the game in the chat or in the leaderboard, for example.
Contains information about the player's current pet, nil if the player does not have a pet.
The User object containing the player's Highrise account information.
Use player.user.id for persistent user identification.
Use player.name as a shortcut for player.user.name.
local user = player.user
print("Name: " .. user.name)
print("ID: " .. user.id)
print("Subscriber: " .. tostring(user.isSubscriber))
-- Store user-specific data
Storage.SetPlayerValue(player, "Score", 100)
-- Add to leaderboard
Leaderboard.SetScore("global", player.user.id, player.name, 1000)
When proximity chat is enabled, voice position is the position used for this player when calculating voice volume. If this is not set, the character's position is used.
If this player is speaking, this returns the volume of their voice on a scale from 0-1.
Methods
Returns whether the player is currently using a pet of the specified type. This type matches the value returned by player.pet.skeletonId.
Parameters
petId
Returns
Returns true if the pet type matches, otherwise false.
Updated 13 days ago