如何使用脚本更改GUI的可见性?

问题描述 投票:0回答:1

我正在努力做到这一点,以便当您单击某个对象时,会出现一个文本框,根据您单击的内容,文本会有所不同,但是由于某些原因,它将无法正常工作。我认为这是因为我错误地指定了GUI,但是我不知道如何正确地进行操作。

我尝试过更改StarterGui和PlayerGui,但似乎都没有用。请告诉我我在做什么错。另外,该游戏是单人游戏,因此无需指定它仅影响一个人。

local Box = game.PlayerGui.ScreenGui.TextBox

local function onClick(playerWhoClicked)
    game.PlayerGui.ScreenGui.Enabled = true
    if workspace.Clues.test.Value == 1
    then
    Box.Text = "Your masters words echo in your head: wi can has can, but wi can't has this yet"
    wait (5)
    game.PlayerGui.ScreenGui.Enabled = false
    else
    Box.Text = "Filipe has been murdered??!?!?"
    wait (5)
    game.PlayerGui.ScreenGui.Enabled = false
    end
    end

script.Parent.MouseClick:Connect(onClick)

我很确定有办法做到这一点,但我不知道怎么做

lua roblox
1个回答
0
投票

对于所有玩家都是。

local Box = <YOUR TEXTBOX>

local function onClick(playerWhoClicked)
    Box.Enabled = true
    if workspace.Clues.test.Value == 1 then
        Box.Text = "Your masters words echo in your head: wi can has can, but wi can't has this yet"
        wait (5)
        Box.Enabled = false
    else
        Box.Text = "Filipe has been murdered??!?!?"
        wait (5)
        Box.Enabled = false
    end
end

script.Parent.MouseClick:Connect(onClick)

问题在于文本框的位置,因为“ game.PlayerGui”不是“ game.Players.PlayerGui”(我希望这会有所帮助。)

© www.soinside.com 2019 - 2024. All rights reserved.