Roblox 脚本只能运行一次

发布于 2025-01-18 15:02:12 字数 617 浏览 3 评论 0原文

我正在编写一个脚本,可以改变你的团队并在你死后打开一个 Gui,但它只能工作一次。

这是我的脚本,我将其放入 ServerScriptSevice 中:

game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
        
 local gui = player.PlayerGui:FindFirstChild("TeamGUI"):WaitForChild("Background") 

        player.TeamColor = game.Teams:findFirstChild("Choosing").TeamColor
        
        wait(3)

        gui.Visible = true
                
        end)
    end)
end)

我不知道为什么,但只有 Teamcolor 可以工作几次,而 Gui 可以工作一次。

I'm working on a script that change your team and open a Gui when you die, but it only work onetime.

Here is my script, I put it into ServerScriptSevice:

game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
        
 local gui = player.PlayerGui:FindFirstChild("TeamGUI"):WaitForChild("Background") 

        player.TeamColor = game.Teams:findFirstChild("Choosing").TeamColor
        
        wait(3)

        gui.Visible = true
                
        end)
    end)
end)

I don't know why but only the Teamcolor works several times and the Gui once.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾其所爱 2025-01-25 15:02:12

这是因为您的事件仅在玩家加入时才有效,

您的脚本如下所示:
玩家加入 AND 死亡,然后 gui 出现,

您需要执行以下操作:

玩家加入 OR

在 LocalScript 中像这样

local plr = game:GetService('Players').LocalPlayer
plr.CharacterAdded:Connect(function() -- when character loads (Player Joins or Die) your gui should appear
   local gui = player.PlayerGui:FindFirstChild("TeamGUI"):WaitForChild("Background")
   plr.TeamColor = game.Teams:findFirstChild("Choosing").TeamColor
   wait(3)
   gui.Visible = true
end)

死亡,尝试此操作,如果不起作用,则发表评论

it's because your event works only when player joins

your script works like:
Player joined AND died then gui appears

you need to do:

Player Joined OR Dies

like this in LocalScript

local plr = game:GetService('Players').LocalPlayer
plr.CharacterAdded:Connect(function() -- when character loads (Player Joins or Die) your gui should appear
   local gui = player.PlayerGui:FindFirstChild("TeamGUI"):WaitForChild("Background")
   plr.TeamColor = game.Teams:findFirstChild("Choosing").TeamColor
   wait(3)
   gui.Visible = true
end)

try this, if its not work then comment

财迷小姐 2025-01-25 15:02:12

在这里尝试一下,它应该

local plr = game.Players.LocalPlayer    
local character = plr.LocalPlayer.Character or plr.LocalPlayer.CharacterAdded:Wait()

character.Humanoid.Died:Connect(function()
  local gui = plr.PlayerGui:FindFirstChild("TeamGUI"):WaitForChild("Background")
  plr.TeamColor = game.Teams:FindFirstChild("Choosing").TeamColor
  wait(3)
  gui.Visible = true
end)

基本上起作用我所做的是设置一个事件,每当您的角色死亡时都会听

here try this, it should work

local plr = game.Players.LocalPlayer    
local character = plr.LocalPlayer.Character or plr.LocalPlayer.CharacterAdded:Wait()

character.Humanoid.Died:Connect(function()
  local gui = plr.PlayerGui:FindFirstChild("TeamGUI"):WaitForChild("Background")
  plr.TeamColor = game.Teams:FindFirstChild("Choosing").TeamColor
  wait(3)
  gui.Visible = true
end)

basically what I did was set up an event that listens for whenever your character has died

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文