SurfaceGui update problem

Before any thing!! Just to let you know I’m not best at speaking English!

  1. What do you want to achieve? Keep it simple and clear!
    I need to make script that when player is registered on Gui player name and problem shows up on surface gui. There should be max 4 registered players at time on part in workspace. And when player leaves gui of that player needs to be removed (I didn’t try to make this because I was trying to fix this bug)

  2. What is the issue? Include screenshots / videos if possible!
    Issue is that when I make like second registration on gui (that should pop out on part in workspace) the first updates his information’s like that’s second gui.

This is screen shoot when I first register player:

This is screen shoot when I try to register next player:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried looking around forum and YouTube videos but it didn’t help out.

This is code that should do all work:


local registeredPlayers = 0

RS.SurfaceGuiUpdate.OnServerEvent:Connect(function(player, userInfo, sender)

	userInfo.userName = tostring(userInfo.userName)
	userInfo.userProblem = tostring(userInfo.userProblem)
	if registeredPlayers == 0 then
		local newText = workspace.something.Screen.orginal:FindFirstChild("Patient"):Clone()
		newText.Parent = workspace.something.Screen.orginal
		newText.Name = userInfo.userName
		newText.Text = userInfo.userName .. " - " ..userInfo.userProblem
		newText.Position += UDim2.new(0,0,0.2,0)
		newText.Visible = true
		print("Player: " ..tostring(player).. ", made registration for: ".. tostring(userInfo.userName) .. " problem is: ".. tostring(userInfo.userProblem))
		
	elseif registeredPlayers == 1 then
		local newText = workspace.something.Screen.orginal:FindFirstChild("Patient"):Clone()
		newText.Parent = workspace.something.Screen.orginal
		newText.Name = userInfo.userName
		newText.Text = userInfo.userName .. " - " ..userInfo.userProblem
		newText.Position += UDim2.new(0,0,0.4,0)
		newText.Visible = true
		print("Player: " ..tostring(player).. ", made registration for: ".. tostring(userInfo.userName) .. " problem is: ".. tostring(userInfo.userProblem))

	elseif registeredPlayers == 2 then
		local newText = workspace.something.Screen.orginal:FindFirstChild("Patient"):Clone()
		newText.Parent = workspace.something.Screen.orginal
		newText.Name = userInfo.userName
		newText.Text = userInfo.userName .. " - " ..userInfo.userProblem
		newText.Position += UDim2.new(0,0,0.8,0)
		newText.Visible = true
		print("Player: " ..tostring(player).. ", made registration for: ".. tostring(userInfo.userName) .. " problem is: ".. tostring(userInfo.userProblem))
		
	elseif registeredPlayers == 3 then
		local newText = workspace.something.Screen.orginal:FindFirstChild("Patient"):Clone()
		newText.Parent = workspace.something.Screen.orginal
		newText.Name = userInfo.userName
		newText.Text = userInfo.userName .. " - " ..userInfo.userProblem
		newText.Position += UDim2.new(0,0,0.12,0)
		newText.Visible = true
		print("Player: " ..tostring(player).. ", made registration for: ".. tostring(userInfo.userName) .. " problem is: ".. tostring(userInfo.userProblem))
	elseif registeredPlayers == 4 then		
	end
end)
2 Likes

Try printing the registeredPlayers variable every time it fires the event.

Nope, still the same same issue happens.

The point was to figure out if registeredPlayers change at all, I have a feeling it’s stuck at 0.

your didnt set the right position, so it will just cover the previous one or be hidden if you put it off the part’s surface

I think you would need a UIGridLayout instance to position these slots on your surface gui. Not sure if the code is working and setting the text of these slots though.

You don’t seem to update the registeredPlayers value so in this code alone it is always 0. Also you have lots of repeating code to do essentially the same thing, apart from repositioning the text. A good mantra in programming is this: “If you find yourself repeating code over and over, you are doing it wrong!”. You just need a single interface to make the text since the position is managed by the number of players and the text offset. Try this:

local registeredPlayers = 0;
local textOffset = 0.2;

RS.SurfaceGuiUpdate.OnServerEvent:Connect(function(player, userInfo, sender)

	userInfo.userName = tostring(userInfo.userName)
	userInfo.userProblem = tostring(userInfo.userProblem)
	local newText = workspace.something.Screen.orginal:FindFirstChild("Patient"):Clone()
	newText.Parent = workspace.something.Screen.orginal
	newText.Name = userInfo.userName
	newText.Text = userInfo.userName .. " - " ..userInfo.userProblem
	newText.Position += UDim2.new(0,0,(registeredPlayers+1)*textOffset,0)
	newText.Visible = true
	print("Player: " ..tostring(player).. ", made registration for: ".. tostring(userInfo.userName) .. " problem is: ".. tostring(userInfo.userProblem))

	-- maybe increase the registeredPlayers value?
	registeredPlayers += 1;
end)
1 Like

Script does work and also I moved script to server script service and I moved text Gui to replicated storage, and now it works :smiley: Thank you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.