我试图在创建一个加载屏幕的脚本中创建该脚本,该屏幕仅应按PlayerAdded函数使用一次。但是当玩家死亡时,加载屏幕会返回。怎么了?
我使用了两种类型的播放器。考虑到服务器刚刚启动并且避免了播放器的脚本,只有一个播放器时,正常的PlayerAdded无效。第二个给我这个问题。
function onPlayerAdded(Player)
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
PlayerGui:SetTopbarTransparency(0)
local LoadingScreen = Player.PlayerGui.LoadingScreen
...
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in pairs(game.Players:GetPlayers()) do
onPlayerAdded(player)
end
答案 0 :(得分:0)
您可以使用ReplicatedFirst:
game.Players.PlayerAdded:Connect(function(plr) game.ReplicatedFirst.LoadingScreen:Clone()。Parent = plr.PlayerGui 结束)
很抱歉,如果我有任何错误,我已经有一段时间没有使用roblox编程了,而且我正在打电话。
答案 1 :(得分:0)
我设想这样的事情:
local players = game:GetService("Players")
-- Assume the loading GUI is a child of script.
local gui = script:WaitForChild("LoadingGui")
local function onPlayerAdded(player)
local playerGui = player:WaitForChild("PlayerGui")
local clone = playerGui:FindFirstChild("LoadingGui")
if (not clone) then
clone = gui:Clone()
clone.Parent = playerGui
end
return
end
players.PlayerAdded:Connect(onPlayerAdded)
onPlayerAdded
每个客户端应仅触发一次,因此GUI仅应按预期出现一次。另外,最好将此代码放在Script
中的LocalScript
中,而不要放在ServerScriptStorage
中。