Duplicating an object depending on the players in-game

Hello, hope you are having a good day or night.

I am currently making a story game and Stage 1 opens with bikes. To reduce lag and add more realism, I want the number of bikes to be the number of players in-game, with the bikes in a specific position so that way the bikes aren’t in random spots of the map.

I don’t know if this is easy or hard; i’m kind of a noob/intermediate scripter and I don’t know all main essentials yet.

Best,
Sun

You can use OnPlayerAdded and PlayerRemoving events to detect when someone joins/leaves. FYI Appropriate topic would be #help-and-feedback:scripting-support.

1 Like

You can make the same number of bikes in a precise moment using:

for index, player in pairs(game.Players:GetPlayers()) do
--the clone of bikes
local newBike = game.ServerStorage.Bike:Clone
-- the position of the bike in front of player (not exactly)
newBike.Cframe = player.Character.CFrame+CFrame.new(5,0,5)
end
1 Like

Well, in this case - players are being teleported from the lobby to the main story, which is essentially how a Story Game works. So if the player were to die, they would either pay R$30 to revive, or be teleported back to the lobby.

After stage one is completed the bikes will be deleted.