Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Whats wrong with this script?

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

1 comment

0

Edit your post to use Lua code formatting.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.