You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
How to check for 1 singular player out of the 4 joining and fire a event to the server.
What is the issue? Include screenshots / videos if possible!
I cannot really test the output but these are the issues I get for the client.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to use # and other types of methods like GetChildren()
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
local mapData = TeleportService:GetTeleportSetting("MapData")
local event = ReplicatedStorage:WaitForChild("getMap")
Players.ChildAdded:Connect(function(player)
if player then
if #Players:GetPlayers() == 1 then
event:FireServer(mapData)
task.wait(0.25)
script:Destroy()
end
end
end)
YES IT DOES WORK, ALL I NEED TO DO IS MAKE IT WORK FOR ONE SINGULAR PLAYER OUT OF THE 4 SO ALL OF THE PLAYERS DON’T FIRE TO SERVER!
Just have the server use a bindable event to handle it.
local TeleportService = game:GetService("TeleportService")
local mapData = TeleportService:GetTeleportSetting("MapData")
local event = --bindable event
local done = false
game.Players.PlayerAdded:Connect(function(plr)
if #game.Players:GetPlayers() == 1 and not done then
event:Fire(mapData)
done = true
end
end)
Edit: Whoops, GetTeleportSetting is only available on the client. So, instead, use a bindable event and a remotefunction. This makes this much less exploitable.
local event = --bindable event
local remfunc = --remove function
local done = false
game.Players.PlayerAdded:Connect(function(plr)
if #game.Players:GetPlayers() == 1 and not done then
event:Fire(remfunc:InvokeClient(plr))
done = true
end
end)
client script
local TeleportService = game:GetService("TeleportService")
local mapData = TeleportService:GetTeleportSetting("MapData")
remevent.OnClientInvoke = function()
return mapData
end
Well, that shows that you don’t actually need the player and it will work fine with a bindable event.
event.Event:Connect(function(mapData)
You could also do this without this much communication, just using the one script I had provided before (partially)
local remfunc = --remove function
local done = false
game.Players.PlayerAdded:Connect(function(plr)
if #game.Players:GetPlayers() == 1 and not done then
local mapData = remfunc:InvokeClient(plr)
if mapData then
maps:WaitForChild(mapData).Parent = workspace.Map
task.wait(5)
workspace.SpawnBox.Floor:Destroy()
else
maps["Grass Lands"].Parent = workspace.Map
task.wait(5)
workspace.SpawnBox.Floor:Destroy()
warn("Default Map Loaded")
end
done = true
end
end)
Im a bit confused, so theres a new script? So the client script that I was on about first thing is in StarterPlayerScripts. So that will become the onClientInvoke one? I really need a summary of which scripts going where, i understand what it does but i am pretty overwhelmed right now.
Alright, sorry for not explaining properly. The first script is a server script, the one that requests the data from the first player that joins, and only once. The second script will be a script inside StarterPlayerScripts like you had thought, which will return the map data.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
local mapData = TeleportService:GetTeleportSetting("MapData")
local event = ReplicatedStorage:WaitForChild("getMap")
Players.PlayerAdded:Connect(function(player)
if player then
if Players:GetPlayers() == 1 then
event:FireServer(mapData)
task.wait(0.25)
script:Destroy()
end
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remfunc = ReplicatedStorage.mapFunction
local done = false
game.Players.PlayerAdded:Connect(function(plr)
if #game.Players:GetPlayers() == 1 and not done then
local mapData = remfunc:InvokeClient(plr)
if mapData then
maps:WaitForChild(mapData).Parent = workspace.Map
task.wait(5)
workspace.SpawnBox.Floor:Destroy()
else
maps["Grass Lands"].Parent = workspace.Map
task.wait(5)
workspace.SpawnBox.Floor:Destroy()
warn("Default Map Loaded")
end
done = true
end
end)
Client Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
local mapData = TeleportService:GetTeleportSetting("MapData")
local event = ReplicatedStorage:WaitForChild("getMap")
event.OnClientInvoke = function()
return mapData
end
Is the client actually receiving any map data? You might want to make sure of that first.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
local mapData = TeleportService:GetTeleportSetting("MapData")
local event = ReplicatedStorage:WaitForChild("getMap")
print(mapData)
event.OnClientInvoke = function()
return mapData
end
What else: Well this is the script for the lobby elevator, which I soon will refer back to once its fixed.
ELEVATOR SCRIPT:
local function TeleportPlayers()
local placeId = config:WaitForChild("PlaceID").Value
local server = TeleportService:ReserveServer(placeId)
local options = Instance.new("TeleportOptions")
options.ReservedServerAccessCode = server
TeleportService:SetTeleportSetting("MapData", mapgui.MapName.Text)
safeTeleport(placeId, playersWaiting, options)
end
I reccomend you mainly look at the SetTeleportSetting part…