Competition countdown and teleportation

So today I was trying to make a sort of small competition with a countdown. Here are my current scripts:

Server Script that counts down and sends out a remote event to the local script below this code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.ArenaEvent
wait(5)

for x=10,0,-1 do
	wait(1)
	print("Sending information to all Clients")
	RemoteEvent:FireAllClients(x)
end
Local Script that receives the data and changes the Textlabel's text
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.ArenaEvent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
local teleportRemoteEvent = ReplicatedStorage.TeleporttoArena

local function onTimerUpdate (x)
	playerGui.Competition.Countdown.Text = "Time to next competition: " .. x .. " seconds!"
	if x <=0 then
		teleportRemoteEvent:FireServer()
	end
end

remoteEvent.OnClientEvent:Connect(onTimerUpdate)

My current issue is that I want to teleport all players to the arena, but I am not sure if I can do that through a local script. When I send information from the Server Script, I send it to all clients, but I am not sure if it would stay working on multiple (or any) clients at all if I used a remoteEvent from there.

All help is appreciated😃

any character based movement is done on the client to prevent input lag. I.E. if the client changes there humandrootpart’s position it will change on the server unlike other client based actions such as moving a brick which will not replicate on the server. this is why movement exploits are difficult to deal with. To asnwer your question you can either set the players HumanoidRootPart on the server via a for loop going through each player in the game and getting the character or you can set the characters humanoidrootpart on the client of that players character. Both will work so its up to you which one you prefer.

I also recommending avoiding firing all the clients thsi often as it could cause memory issues if there is many players. A better option would be to store a string value in replicated storage so the server can change the value directly and the client can listen for changes via a .changed event which is way less memory intensive then firing remote events every second.

Here you will find what you are looking for

https://education.roblox.com/en-us/resources/battle-royale/coding-the-game-loop

1 Like