I’ve been making a round system in my shooter game, everything works awesome but one thing: When new Player wants to join an existing round, he can’t. There is a part of the script in ServerScriptService, it is based on the value in ReplicatedStorage.
function loadMap(mapName:string)
print(mapName)
local newMap = maps[mapName]:Clone()
newMap.Parent = workspace
game.ReplicatedStorage.Booleans.Playing.Value = true --value in ReplicatedStorage, that allows existing players to join a new round, but new ones can't because the value is "false" for them
game.ReplicatedStorage.Booleans.Intermission.Value = false -- ignore it, it's for timer
currentSpawns = newMap:WaitForChild("Spawns"):GetChildren()
return newMap
end
How do I implement this to new players in optimized way to not have a bunch of dognails? Any help is appreciated!
You need to add a PlayerAddedEvent to detect when a new player joins and then you can decide what you want to do with the new Player in order to integrate them into the round,.
game.Players.PlayerAdded:Connect(function(player)
--add code here
end)
So I made this piece of script in ServerScriptService (1) and Local Script (2), but .PlayerAdded event doesn’t fire even on platform. What possibly can I do? Or my local script needs to be in some specific place? Or the game must be public?
local event = game.ReplicatedStorage.IsAvaliable
event.OnClientEvent:Connect(function(plr, val)
game.ReplicatedStorage.Booleans.Playing = val
warn("event fired:", game.ReplicatedStorage.Booleans.Playing.Value, val)
end)
It doesn’t even print in the output, I have no idea how to work with this. I’ve been testing this with my testers to make a player join later than server starts, and that didn’t work too : (
Hmm maybe try putting the plrs.PlayerAdded into the server script instead of using remote events by doing for example game.Players.PlayerAdded. I have made a mistake I forgot that PlayersAdded also work globally
Didn’t mention that I did it too, but as always, didn’t work. So I just remade the code logic to be independent from RemoteEvents. Thanks for help anyway and have a great day!