Lua 管理特定于玩家的变量
我想给玩家通电,但只能在碰到砖头之后。从那时起,通电应该是永久性的。我不需要为以后的游戏会话存储它。为此,我如何存储特定于玩家的信息?我会为每个加入游戏的玩家添加一个“加电”变量(布尔值):Lua 管理特定于玩家的变量,lua,roblox,Lua,Roblox,我想给玩家通电,但只能在碰到砖头之后。从那时起,通电应该是永久性的。我不需要为以后的游戏会话存储它。为此,我如何存储特定于玩家的信息?我会为每个加入游戏的玩家添加一个“加电”变量(布尔值): -- Add a "PowerUp" variable to every player that joins the game game.Players.PlayerAdded:Connect(function(player) local powerUp = Instance.new("BoolVa
-- 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)
我将把这个脚本放在哪里?我将它添加到StarterPlayerScript下的本地脚本中,但它没有被调用,因此显然不是它的正确位置。另外,假设答案是这属于服务器脚本,我将能够从本地脚本访问它(检查播放器是否有通电)。顺便说一句,任何对相关文章的引用都是非常受欢迎的:)我会把它放到ServerScriptService中。这是一个只在服务器上执行脚本的地方(即,它们不会被复制到客户端)。然而,在服务器上创建的“BoolValue”实例将被复制到客户端,因此是的,您可以从客户端脚本中看到它,并且如果值发生变化,您还可以让它向客户端脚本触发事件。