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

Why does the gui show for all the players?

I have a script that when you touch certain bricks a number on a GUI on the screen changes +1. So if the player touches the 5 bricks, then the GUI/TextLabel changes to 5. The problem is that it changes for all the players in-game and I do not know how to fix this, been trying all day.

I am using NumberValue to change the value on the GUI. The NumberValue is in StarterGui in the GUI and is named "ProcentValue".

This is the brick you touch.

local Dbounce = true

script.Parent.Touched:Connect(function(hit)
		
	if Dbounce == true then 
		Dbounce = false
	game.StarterGui.ProcMeter.ProcentValue.Value = game.StarterGui.ProcMeter.ProcentValue.Value +1
	wait(15)
	Dbounce = true
	end
	
end)

This is the script that does so the number can change in the GUI on the screen.

while wait()do

PV = game.StarterGui.ProcMeter.ProcentValue.Value
PV2 = ""..game.StarterGui.ProcMeter.ProcentValue.Value

if PV == 0 then	
script.Parent.Text = PV2
elseif PV == 1 then
	script.Parent.Text = PV2
elseif PV == 2 then
	script.Parent.Text = PV2
elseif PV == 3 then
	script.Parent.Text = PV2
elseif PV == 4 then
	script.Parent.Text = PV2
elseif PV == 5 then
	script.Parent.Text = PV2
elseif PV == 6 then
	script.Parent.Text = PV2
elseif PV == 7 then
	script.Parent.Text = PV2
elseif PV == 8 then
	script.Parent.Text = PV2
elseif PV == 9 then
	script.Parent.Text = PV2
elseif PV == 10 then
       script.Parent.Text = PV2
end
end

Does anyone know why this show for all the players and not only the local player? If you need more information just ask, thanks for the help, Xsodar

4 comments

2

You should only Increment PlayerGui, not StarterGui

0

Just like roblor said, increment a PlayerGui so that only the player can see it, not the whole server.

0

How do I do this if the script is not a localscript?

0

The first script is a normal script and the second one is a localscript.

1 answer

It's pretty simple. Since you didn't call it by the local client, either by the server client. There are 2 clients, 1 is the local client, which is moderating what the local player sees, and the server client is what the entire server sees, like moves of people etc... Because you said "StarterGui", and StarterGui is a part of the server client, the entire server will see it, so, how do we fix it? Super simple. You'll have to go through the PlayerGui, which is basically moderating the local client of the local player. So how you go through it? By this short line.

game.Players.LocalPlayer.PlayerGui

Then, you'll find your target, for example, I have a screengui and then a frame, so I'll do it :

game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame

Now to set it's visibility to true, I'll just reference it like this :

game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true

So, that's it. Just change the StarterGui reference to game.Players.LocalPlayer.PlayerGui. And remember for the next time, there are 2 clients, referencing the server client will cause something for the ENTIRE server, and in the local client will cause something only for the local player. Hope it was clear and you understood it.

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