管理玩家特定变量

我想给玩家一个能力值,但只有在触摸砖块后才能给予。该能力值应从那时起永久存在。我不需要将其存储到后续的游戏会话中。我该如何存储这种特定于玩家的信息?

点赞
用户1296374
用户1296374

我会为每一个加入游戏的玩家添加一个“PowerUp”变量(BoolValue):

-- 为每个加入游戏的玩家添加“PowerUp”变量
game.Players.PlayerAdded:Connect(function(player)
    local powerUp = Instance.new("BoolValue", player)
    powerUp.Name = "PowerUp"
end)

-- 当玩家触碰部件时,将“PowerUp”设置为true
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)
2020-05-08 17:34:09