generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Only works once

Previous Thread :: Next Thread 
instawin is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image