RemoteEvent not Transferring a Value between the Client/Server

Here’s the local script:

local button = script.Parent
local Event = game.ReplicatedStorage.Events.StartGame
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

button.MouseButton1Click:Connect(function()
   Event:FireServer(LocalPlayer.Level.Value)
   warn("Value is " .. LocalPlayer.Level.Value)
end)

And here’s the normal script:

local HostLevel = 0

local function gameStarted(Level)
	HostLevel += Level
end

wait(1)
warn(HostLevel)

game.ReplicatedStorage.Events.StartGame.OnServerEvent:Connect(gameStarted)

image

Why does it do this and how do I solve it?

Well so lets start with

  1. You are checking if the HostLevel changed before the Remote Event was even connected, then the HostLevel will never change.
  2. You are waiting instead you should put the warn inside the function at the end.

Tl;dr the issue is the server sided script to fix it do:

local HostLevel = 0

local function gameStarted(Player, Level)
	HostLevel += Level
	warn(HostLevel)
end

game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("StartGame").OnServerEvent:Connect(gameStarted)
local button = script.Parent
local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("StartGame")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

button.MouseButton1Click:Connect(function()
   Event:FireServer(LocalPlayer.Level.Value)
end)
local HostLevel = 0

local function AdddLevel(Player,Lvl)
	HostLevel += Lvl
	warn(HostLevel)
end

game.ReplicatedStorage.Events.StartGame.OnServerEvent:Connect(AddLevel)
1 Like

Don’t forget to provide the Player as the first argument. When using FireServer, on the server call, it always has to be the first param. [Even though you dont use it in the function in this case].

This works, but now if I run
for wave=1, Level do
It says that it’s an Instance, not a number.