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.
--// 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:
If I’m correct, the variables should be local DefenseScore = Defense.Score.InputText
…and the server activaters should be DefenseScoreRemote:FireServer(DefenseScore.Text)
I found out my problem, the code I accidentally typed was local DefenseScore = Defense.Score.InputText instead of local DefenseScore = Defense.Score.ScoreText.