管理玩家特定变量
Managing player specific variable
我想给玩家加电,但只有在接触到砖块之后。从那时起,通电应该是永久性的。我不需要为以后的游戏会话存储它。为此,我如何存储特定于玩家的信息?
我会为每个加入游戏的玩家添加一个 "PowerUp" 变量 (BoolValue):
-- Add a "PowerUp" variable to every player that joins the game
game.Players.PlayerAdded:Connect(function(player)
local powerUp = Instance.new("BoolValue", player)
powerUp.Name = "PowerUp"
end)
-- Set "PowerUp" to true, when player touches part
script.Parent.Touched:Connect(function(touchedPart)
local char = touchedPart.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if (player == nil) then return end
player.PowerUp.Value = true
end)
我想给玩家加电,但只有在接触到砖块之后。从那时起,通电应该是永久性的。我不需要为以后的游戏会话存储它。为此,我如何存储特定于玩家的信息?
我会为每个加入游戏的玩家添加一个 "PowerUp" 变量 (BoolValue):
-- Add a "PowerUp" variable to every player that joins the game
game.Players.PlayerAdded:Connect(function(player)
local powerUp = Instance.new("BoolValue", player)
powerUp.Name = "PowerUp"
end)
-- Set "PowerUp" to true, when player touches part
script.Parent.Touched:Connect(function(touchedPart)
local char = touchedPart.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if (player == nil) then return end
player.PowerUp.Value = true
end)