You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Mages_Boss被击败时显示DemonWin GUI?

解决Roblox中击败Boss后显示指定GUI的问题

嘿,我来帮你搞定这个问题!你想要在名为Mages_Boss的角色被击败时显示DemonWin的GUI,目前你的代码里有几个需要调整的地方,尤其是print("good")的替换部分,我给你详细说明:

首先要注意的是:不要直接修改StarterGui里的内容!StarterGui只是GUI的初始模板,玩家进入游戏后,这些GUI会被复制到每个玩家的PlayerGui文件夹中,所以我们需要操作PlayerGui里的实际GUI实例,而不是模板。

另外你的原代码还有语法问题,connect应该写成大写的Connect(Roblox Lua的标准事件绑定写法),而且函数的闭合逻辑也不完整。

方案1:服务器端脚本(适用于所有玩家同步显示GUI)

如果你的脚本是放在ServerScriptService或者Workspace里的服务器脚本,可以用这段代码,它会在Boss死亡时给所有在线玩家显示GUI:

-- 先找到Boss对象和它的Humanoid
local magesBoss = game.Workspace:FindFirstChild("Mages_Boss")
if not magesBoss then
    warn("Mages_Boss 没在Workspace里找到!")
    return
end

local bossHumanoid = magesBoss:FindFirstChildOfClass("Humanoid")
if not bossHumanoid then
    warn("Mages_Boss 没有Humanoid组件!")
    return
end

-- 绑定Boss死亡事件
bossHumanoid.Died:Connect(function()
    -- 遍历所有在线玩家
    for _, player in ipairs(game.Players:GetPlayers()) do
        local playerGui = player:FindFirstChild("PlayerGui")
        if playerGui then
            -- 找到对应的GUI元素
            local screenGui = playerGui:FindFirstChild("ScreenGui1")
            local demonWin = screenGui and screenGui:FindFirstChild("DemonWin")
            
            if demonWin then
                demonWin.Visible = true
            else
                warn("玩家" .. player.Name .. "的PlayerGui里没找到DemonWin!")
            end
        end
    end
end)

方案2:本地脚本(仅给当前玩家显示GUI)

如果你的脚本是放在玩家的PlayerScripts或者StarterPlayerScripts里的本地脚本,可以简化成这样,只处理本地玩家的GUI:

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

-- 找到Boss的Humanoid
local magesBoss = game.Workspace.Mages_Boss
local bossHumanoid = magesBoss.Humanoid

-- 绑定死亡事件
bossHumanoid.Died:Connect(function()
    -- 直接修改本地玩家的GUI可见性
    playerGui.ScreenGui1.DemonWin.Visible = true
end)

关键修正点说明

  • 替换print("good")的核心代码就是设置DemonWin.Visible = true,但要确保你操作的是PlayerGui里的实例,而不是StarterGui的模板。
  • 加上错误检查(比如判断对象是否存在)可以避免脚本因为找不到对象而崩溃。
  • 服务器脚本和本地脚本的选择取决于你是要给所有玩家显示,还是只给击杀Boss的玩家显示(如果是后者,本地脚本更合适)。

内容的提问来源于stack exchange,提问作者Dang Khoa Chiem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:55:52