How to only change gui on client side

I am trying to make a surface GUI display a value inside of the player so for each play it will display THEIR values but for some reason it counts for both so if one players value goes up the surface GUI changes for them and myself instead of just for the individual person.

Code:

v.DisplayPart.SurfaceGui.TextLabel.Text = Player.Gems.Gems.Value.."/"..Player.Gems.TotalGems.Value

Please send the full code, my guess is you chose wrong player, try using game.Players.LocalPlayer

local Levels = game.Workspace.Levels:GetChildren()
local Player = game.Players.LocalPlayer

for _,v in pairs(Levels) do
	local Gems = v.Gems
	for _,f in pairs(v.Gems:GetChildren()) do
		f.Touched:Connect(function(player)
			Player.Gems.Gems.Value += 1
			v.DisplayPart.SurfaceGui.TextLabel.Text = Player.Gems.Gems.Value.."/"..Player.Gems.TotalGems.Value
			f.Transparency = 1
			f.CanTouch = false
			if Player.Gems.Gems.Value >= Player.Gems.TotalGems.Value then
				game.Players[player.Parent.Name].PlayerGui.TimerGui.TextLabel.TextColor3 = Color3.new(0.180392, 1, 0)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.TextLabel.Text = "Complete!"
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
				wait(0.3)
				game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
				game.Players[player.Parent.Name].leaderstats.Level.Value += 1
				Player.Gems.Gems.Value = 0
				player.Parent.HumanoidRootPart.CFrame = game.Workspace.Levels["L"..tostring(game.Players[player.Parent.Name].leaderstats.Level.Value)].TpPart.CFrame
				f.Transparency = 0
				f.CanTouch = true
			end
		end)
	end
end

You should check if touched player is localplayer
Also why do you give gems in client?

How would I do that and I don’t know why I gave them gems in client but I want this problem fixed first.

if player == Player then
#your code here
end

Make this into a local script, the only reason it’s changing for all players is because it’s a server script. :slight_smile:

How can he use localplayer if its a server script :man_facepalming:

I did what you said and it is infact in a local script but it still does not work

local Levels = game.Workspace.Levels:GetChildren()
local Player = game.Players.LocalPlayer

for _,v in pairs(Levels) do
	local Gems = v.Gems
	for _,f in pairs(v.Gems:GetChildren()) do
		f.Touched:Connect(function(player)
			if player == Player then
				Player.Gems.Gems.Value += 1
				v.DisplayPart.SurfaceGui.TextLabel.Text = Player.Gems.Gems.Value.."/"..Player.Gems.TotalGems.Value
				f.Transparency = 1
				f.CanTouch = false
				if Player.Gems.Gems.Value >= Player.Gems.TotalGems.Value then
					game.Players[player.Parent.Name].PlayerGui.TimerGui.TextLabel.TextColor3 = Color3.new(0.180392, 1, 0)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.TextLabel.Text = "Complete!"
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = true
					wait(0.3)
					game.Players[player.Parent.Name].PlayerGui.TimerGui.Enabled = false
					game.Players[player.Parent.Name].leaderstats.Level.Value += 1
					Player.Gems.Gems.Value = 0
					player.Parent.HumanoidRootPart.CFrame = game.Workspace.Levels["L"..tostring(game.Players[player.Parent.Name].leaderstats.Level.Value)].TpPart.CFrame
					f.Transparency = 0
					f.CanTouch = true
				end
			end
		end)
	end
end

The code just does not even run how it did before

i recommend you learning basics of roblox studio and basic programming, there are pretty good tutorials out there

Ok you should do if player == game.Players:GetPlayerFromCharacter(Player.Parent) then

It just does not work at all anymore

image

By converting it to work on a local script. I did not mean simply copy paste it into a local script.

local Player = game.Players.LocalPlayer

For one the server does not have local player

It already have it in a local script and with that exact line of code

Can you reexplain the problem in greater detail please?

In my game you collect gems I want to display the amount of gems the player has collected on a surface GUI but the problem is that when anyone touches a gem it changes the surface GUI text for every instead of just that one specific player.

So when somebody’s Gems goes up, the entire server’s gems go up?

ya and it stacks on (These are random words so I can send)

Okay my bad I misuderstood your question. Change it back to how you had it originally.

I see the problem.

The problem is one this line. You are referencing Player not player.
In fact remove the

local Player = game.Players.LocalPlayer

As the server (where this script is ran) does not have a local player.
You are just adding gems to this single “Player”

1 Like