Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whats wrong with this script?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I'm trying to make a script where if someone clicks the button. The whole Gui gets deleted on the players user. Other players will also get the GUI still

Here's the script

function onClicked(playerWhoClicked) Instance.destroy("game.StarterGui.ScreenGui) end

script.Parent.TextButton.MouseClick:connect(onClicked)

Now here's the output

12:53:04.105 - Players.Player1.PlayerGui.ScreenGui.Frame.TextButton.Script:2: unfinished string near '"game.StarterGui.ScreenGui)'

can someone tell me the correct script

0
Edit your post to use Lua code formatting. BlueTaslem 18071 — 8y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

You have a couple problems here. First of all, the Player's GUIs are not stored in StarterGui, but rather in PlayerGui (which is located under their Player object). You should modify it so that it destroys the GUI located in PlayerGui rather than StarterGui.

Which leads me to the next problem. You are accessing the Destroy method as if it where a property when it is actually a function. In order to call a function you need to access it with a colon (:) and you need to end it with a set of parenthesis (()). So calling the destroy method would look like object:Destroy() (note the capital 'D', Lua is case sensitive).

Additionally, we should check to make sure the GUI you are trying to destroy exists first so we don't throw an error upon additional clicks.

So here would be your fixed script:

function onClicked(playerWhoClicked)
    local GUI = playerWhoClicked.PlayerGui:FindFirstChild("ScreenGui")
    if GUI then
        GUI:Destroy()
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
Ad

Answer this question