Remote event returning Player.Name instead of appropriate value

I am currently making a stopwatch system that starts when a part is touched, and ends when another part is touched. When the EndPart is touched, a RemoteEvent fires to the server to send a system message through the chat. However, the issue with this is that the parameter used to fire the RemoteEvent is returning my Player.Name intead of the appropriate value (which would be MainUI.Text).

Local script code:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")

local RemoteEvent = game.ReplicatedStorage:FindFirstChild("toSysMessage")

local PlayerUI = Player.PlayerGui
local ScreenGUI = PlayerUI:WaitForChild("Stopwatch")
local MainUI = ScreenGUI:FindFirstChild("MainUI")

local StartPart = game.Workspace:FindFirstChild("StartPart")
local EndPart = game.Workspace:FindFirstChild("EndPart")

local Started = false

local function IsHuman(instance)
	if instance.Parent:FindFirstChild("Humanoid") then
		return true
	end
	return false
end

local function StartPartTouched(hit)
	if IsHuman(hit) and not Started then
		Started = true
		repeat MainUI.Text = MainUI.Text + 0.1 wait(0.1) until not Started
	end
end

local function EndPartTouched(hit)
	if IsHuman(hit) and Started then
		Started = false
		MainUI.TextColor3 = Color3.fromRGB(255, 170, 0)
		RemoteEvent:FireServer(MainUI.Text) -- REMOTE EVENT BEING FIRED
	end
end

local function HumanoidDied()
	if Started then
		Started = false
		MainUI.Text = 0.0
	end
end

StartPart.Touched:Connect(StartPartTouched)
EndPart.Touched:Connect(EndPartTouched)
Humanoid.Died:Connect(HumanoidDied)

Server script code:

local RemoteEvent = game.ReplicatedStorage:FindFirstChild("toSysMessage")

RemoteEvent.OnServerEvent:Connect(function(Time)
	print(Time)
end)

Reproduction Steps:

3 Likes

The first argument passed into OnServerEvent is always the player who fired the remote.

Try this:

RemoteEvent.OnServerEvent:Connect(function(Player, Time)
	print(Player)
	print(Time)
end)
5 Likes

OnServerEvent has player automatically sent so
RemoteEvent.OnServerEvent:Connect(function(Time)
would be
RemoteEvent.OnServerEvent:Connect(function(Player, Time)

1 Like

The first parameter in OnServerEvent is the Player (Client) that fired the remote event
Your method parameter list should look like

OnServerEvent:Connect(function(PlayerWhoFired, Time)

end)
1 Like

Thanks! Iā€™m a bit rusty in RemoteEvents so I feel mildly stupid for not catching this error. @Blokav @AlexTech01 @punyman9