instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 10 Jul 2015 04:58 PM |
why?
the function getRandomObject(parent) gets a random child from the provided parent, and returns it
plrCount is an int value i use to keep track of players ready to play the game
lobbytag is a stringvalue that i insert into the player when .OnServerEvent fires for the increasePlrCount remote event
lobbySpawns is a model of bricks that are inside of the lobby, they are placed where i want the player to "spawn"
function onCharAdded(char) wait(.3) local plr = game.Players:GetPlayerFromCharacter(char) if plr:FindFirstChild("LobbyTag") then print("moving "..plr.Name.." to a random lobby spawn") local randSpawn = lobbySpawns:GetChildren()[math.random(1, #lobbySpawns:GetChildren())] print(randSpawn.Name) char:MoveTo(randSpawn.Position + Vector3.new(0,3,0)) end end
increasePlrCount.OnServerEvent:connect(function(plr, ...) local tuple = {...} if tuple[1] == "IncreasePlrCount" then local lobbyTag = Instance.new("StringValue", plr) -- to keep track of whether the player is in the lobby or not. the tag only exists if they are in the lobby.
lobbyTag.Name = "LobbyTag" plr:LoadCharacter() print(plr.Name.." has joined the game!") local char = plr.Character char:MoveTo(getRandomObject(lobbySpawns).Position + Vector3.new(0, 3, 0))
increasePlrCount:FireClient(plr, "FixCamera") -- when i fire back to the client, a function connected to .OnClientEvent fixes their camera onto their character, since it was focused on something else.
plrCount.Value = plrCount.Value + 1 hum = char:WaitForChild("Humanoid") print("hum loaded") hum.Died:connect(function() print(hum.Parent.Name.." has died") local char = hum.Parent local plr = game.Players:GetPlayerFromCharacter(char) if plr:FindFirstChild("LobbyTag") then print(plr.Name.." is being reloaded") deadEffects(char) wait(LOBBY_RESPAWN_TIME) char:Destroy() print(char.Parent) plr:LoadCharacter() end end) local connection = plr.CharacterAdded:connect(onCharAdded) end end |
|
|
| Report Abuse |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 10 Jul 2015 05:02 PM |
game.Players.PlayerAdded:connect(function(player) player.characterAdded:connect(function(char) --code end) end)
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 10 Jul 2015 05:03 PM |
oh and i forgot
at the top of the script, game.Players.CharacterAutoLoads is false
and deadEffect(char) is a function that gets all of the character's children, and makes them transparent if it is a basepart |
|
|
| Report Abuse |
|