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

Help fixing a script that is opens ScreenGui?

So I have this code:

game.Players.PlayerAdded:connect(function(player)
script.Parent.MouseButton1Click:connect(function()
gui = player.PlayerGui-- Need to locate playerGui
gui.ScreenGui.Frame1.Visible = true
end
)
end)

This is a normal script inside a SurfaceGui Button.

The problem with this if any player in the game clicks it, the Gui Comes up for everyone in the game. How could I make this so that the Gui comes up only for the person who clicks it? Thanks in advance

1 answer

Problem

You want it to display for ONE player only.

Solution

You are using a PlayerAdded function, and such, each player is recorded. Instead, you should get the LocalPlayer.

Suggestions

Fix the indentation and change the variables to be local. Also, you're only using the gui variable once, so you don't need it.

Final Script

script.Parent.MouseButton1Click:connect(function()
	local plr = game:GetService("Players").LocalPlayer
	plr.PlayerGui.ScreenGui.Frame1.Visible = true
end)

EDIT: THIS HAS TO BE A LOCALSCRIPT IN THE TEXT BUTTON

Remember, if this helped, be sure to hit that like button and accept my answer! It helps both of us!

3 comments

0

It works in studio but not in-game!

0

Local Scripts don't work in workspace, and regular scripts can't access PlayerGui or LocalPlayer.

0

Oops, sorry! I edited the answer

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