Retrieve Data from Client to Server [RESOLVED]

Hey!

I just finished working on a script where if someone click a button, it will send data to the server and then display it via a ScreenGui. I’ve got all of the variables inside of the server script, but how would I retrieve the data from it?

I rarely use RemoteEvents, because most of the time I do not need to use then. However this time, I really do need to use it, so sorry if this post sounds extremely dumb.

Client-Side Script

--// Variables
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
wait(0.1)

local ScoreGui = PlayerGui.ScoreGUI
local Offense = ScoreGui.Background.Offense
local Defense = ScoreGui.Background.Defense
wait(0.1)

local OffenseName = Offense.Username.InputText.Text
local OffenseScore = Offense.Score.ScoreText.Text

local DefenseName = Defense.Username.InputText.Text
local DefenseScore = Defense.Username.InputText.Text
wait(0.1)

--// Script
script.Parent.MouseButton1Click:Connect(function()
	local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
	local OffenseScoreRemote = Remotes.OffenseScore
	local OffenseNameRemote = Remotes.OffenseName
	
	local DefenseScoreRemote = Remotes.DefenseScore
	local DefenseNameRemote = Remotes.DefenseName
	
	OffenseNameRemote:FireServer(OffenseName)
	OffenseScoreRemote:FireServer(OffenseScore)
	DefenseNameRemote:FireServer(DefenseName)
	DefenseScoreRemote:FireServer(DefenseScore)
end)

Server-Side Script

--// Variables
local Stadium = game:GetService("Workspace").Stadium
local LeftTV = Stadium["TVRig-Left"]
local RightTV = Stadium["TVRig-Right"]

	--// Left TV Text
	local LeftTV_OffenseScore = LeftTV.SurfaceGui.Offense.Score.ScoreText.Text
	local LeftTV_OffenseName = LeftTV.SurfaceGui.Offense.Username.UserText.Text
	
	local LeftTV_DefenseScore = LeftTV.SurfaceGui.Defense.Score.ScoreText.Text
	local LeftTV_DefenseName = LeftTV.SurfaceGui.Defense.Username.UserText.Text
	
	--// Right TV Text
	local RightTV_OffenseScore = RightTV.SurfaceGui.Offense.Score.ScoreText.Text
	local RightTV_OffenseName = RightTV.SurfaceGui.Offense.Username.UserText.Text
	
	local RightTV_DefenseScore = RightTV.SurfaceGui.Defense.Score.ScoreText.Text
	local RightTV_DefenseName = RightTV.SurfaceGui.Defense.Username.UserText.Text
	

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local OffenseScoreRemote = Remotes.OffenseScore
local OffenseNameRemote = Remotes.OffenseName

local DefenseScoreRemote = Remotes.DefenseScore
local DefenseNameRemote = Remotes.DefenseName

I know that I only have the variables down, but it baffles me whenever I try to get data from the client.

I suggest using return.

return should be a good retriever. I’ve used it a lot in my previous games.

To get the data from a remote event, you would have it like this:

RemoteEvent.OnServerEvent:Connect(function(Player, Arg1, Arg2, Arg3, ...)
	-- Processing code goes here
end)

The Player argument is always going to have a value, but the other ones may not. You can also rename the Arg1 through Arg__ things too.

Alright, so from my code, what arguments would I need to input?

The naming doesn’t matter, you can call it name or value or number or cat. It’s really up to you! They’re basically just variable names.

I would recommend using “Score” for your score remotes, and “Name” for your name remotes!

Okay… so it would be:

RemoteEvent.OnServerEvent:Connect(function(plr, var1)
	-- Code here
end)

But would I need to change my client-sided scripts to be the same as the server-sided script?

Yeah.

Nope! You can have completely different names on the server to what is on the client, and vice versa.

That’s odd, whenever I go to update the board, it won’t copy over the names. I don’t have scripts for the buttons yet, so I can use those.

What’s your new code look like?

Here it is client-sided:

--// Variables
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui

local ScoreGui = PlayerGui.ScoreGUI
local Offense = ScoreGui.Background.Offense
local Defense = ScoreGui.Background.Defense

local OffenseName = Offense.Username.InputText.Text
local OffenseScore = Offense.Score.ScoreText.Text

local DefenseName = Defense.Username.InputText.Text
local DefenseScore = Defense.Username.InputText.Text

--// Script
script.Parent.MouseButton1Click:Connect(function()
	local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
	local OffenseScoreRemote = Remotes.OffenseScore
	local OffenseNameRemote = Remotes.OffenseName
	
	local DefenseScoreRemote = Remotes.DefenseScore
	local DefenseNameRemote = Remotes.DefenseName
	
	OffenseNameRemote:FireServer(OffenseName)
	OffenseScoreRemote:FireServer(OffenseScore)
	DefenseNameRemote:FireServer(DefenseName)
	DefenseScoreRemote:FireServer(DefenseScore)
end)

And here it is server-sided:

--// Variables
local Stadium = game:GetService("Workspace").Stadium
local LeftTV = Stadium["TVRig-Left"]
local RightTV = Stadium["TVRig-Right"]

	--// Left TV Text
	local LeftTV_OffenseScore = LeftTV.SurfaceGui.Offense.Score.ScoreText.Text
	local LeftTV_OffenseName = LeftTV.SurfaceGui.Offense.Username.UserText.Text
	
	local LeftTV_DefenseScore = LeftTV.SurfaceGui.Defense.Score.ScoreText.Text
	local LeftTV_DefenseName = LeftTV.SurfaceGui.Defense.Username.UserText.Text
	
	--// Right TV Text
	local RightTV_OffenseScore = RightTV.SurfaceGui.Offense.Score.ScoreText.Text
	local RightTV_OffenseName = RightTV.SurfaceGui.Offense.Username.UserText.Text
	
	local RightTV_DefenseScore = RightTV.SurfaceGui.Defense.Score.ScoreText.Text
	local RightTV_DefenseName = RightTV.SurfaceGui.Defense.Username.UserText.Text
	

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local OffenseScoreRemote = Remotes.OffenseScore
local OffenseNameRemote = Remotes.OffenseName

local DefenseScoreRemote = Remotes.DefenseScore
local DefenseNameRemote = Remotes.DefenseName

--// Script
OffenseNameRemote.OnServerEvent:Connect(function(player, data)
	LeftTV_OffenseName = data
	RightTV_OffenseName = data
end)
OffenseScoreRemote.OnServerEvent:Connect(function(player, data)
	LeftTV_OffenseScore = data
	RightTV_OffenseScore = data
end)
DefenseNameRemote.OnServerEvent:Connect(function(player, data)
	LeftTV_DefenseName = data
	RightTV_DefenseName = data
end)
DefenseScoreRemote.OnServerEvent:Connect(function(player, data)
	LeftTV_DefenseScore = data
	RightTV_DefenseScore = data
end)

You are setting LeftTV_OffenseScore (and the other variables in similar situations) to the string that is held in the text content. You should remove the .Text part from each of them. Then, in the OnServerEvent bit, you should have it like this:

LeftTV_OffenseName.Text = data

That made it update my ScreenGui, which is good.
The only bad part about this is that one of the scores and both the names are removed.

You should do the same change that I suggested, but in the client script as well, for these variables:
image

If I’m correct, the variables should be local DefenseScore = Defense.Score.InputText
…and the server activaters should be DefenseScoreRemote:FireServer(DefenseScore.Text)

Yep!

I tried that in my script, but updating it will not post it onto the ScreenGui.

Again send the scripts please, I’ll look through them and see if I can find the issue.

I found out my problem, the code I accidentally typed was local DefenseScore = Defense.Score.InputText instead of local DefenseScore = Defense.Score.ScoreText.

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