I am making a FFA/TDM game where players can enter the game by pressing a button. The button is inside a ScreenGui which is inside the StarterGui. The script inside the button is a localscript
Code (LocalScript):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remfunction = ReplicatedStorage:WaitForChild( "Spawn")
script.Parent.MouseButton1Click:Connect(function()
local Spawn = remfunction:InvokeServer()
print("You have been teleported")
end)
ServerCode (On recieving command)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remfunction = ReplicatedStorage:WaitForChild("Spawn")
local function Deploy (player)
print (player.Name.."wants to deploy")
local status = game.ServerStorage.GameState
print("variables defined")
local character = player.Character
status:GetPropertyChangedSignal("Value"):Connect(function()
if status.Value == "1" then
local ServerStorage = game:GetService("ServerStorage")
local map = game:GetService("ServerStorage").CurrentMap.Value
local spawnpoints = map:FindFirstChild("SpawnPoints")
local AvailableSpawnPoints = spawnpoints:GetChildren()
print("Teleporting function started")
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[math.random(1,#AvailableSpawnPoints)].CFrame + Vector3.new(0,2,0)
wait(2)
print("teleported to spawn")
--Give weapon
local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
if equipped.Value ~= "" then
local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
weapon.Parent = player.Backpack
else
local Sword = ServerStorage.Sword:Clone()
Sword.Parent = player.Backpack
end
print("weapon given")
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = character
print("tag given")
for _, plr in pairs(player) do
if not plr.Team then
local low = 9999
local lowTeam
for _, team in pairs(game:GetService('Teams'):GetChildren()) do
if #team:GetPlayers()<low then
low = #team:GetPlayers()
lowTeam = team
end
end
plr.Team = lowTeam
end
end
print("placed in a team")
print("good to go,start playing!")
else
print("you are in lobby stay there until the timer reaches zero :D")
end
end)
end
remfunction.OnServerInvoke = Deploy()
Output: ServerScriptService.SpawnScript:4: attempt to index local 'player' (a nil value)
Note: The value of GameState changes to 1 every second until the timer ends
The value of GameState switches to 0 after the timer ends
Server Code:
for i = Gamelength,0,-1 do
game.ServerStorage.GameState.Value = "1"
for x, player in pairs(plrs) do
--Code I would not like to show Its similar to the previous server script
else
if character:FindFirstChild("GameTag") then
--They are still alive
print(player.Name.." is still in the game!")
else
--They are dead
-- Code I would not like to show Its similar to the previous server script
end
print("teleported")
end
end
else
table.remove(plrs,x)
print(player.Name.." has been removed!")
end
end
Status.Value = "There are "..i.." seconds remaining"
if i == 0 then
RewardBestTDM(Reward)
print(Status.Value)
break
end
wait(1)
end
end
-- Cleanup Code
Status.Value = "Game ended!"
wait(5)
game.Workspace.GameState.Value = "0"
Please help me!

4 comments
Does it teleport when the timer is 1? You put the if status.Value == "1" then in the localscript, I am not sure which way are you trying to do it, they teleport if the timer is running, or they teleport when the timer ended.
It is supposed to teleport when the timer is running
I just found an error at line 6, Can I make this server sided?
Local scripts cannot access ServerStorage or ServerScriptService