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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: What's wrong with this script?

Previous Thread :: Next Thread 
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 04:44 PM
pcall(function()
if game.Workspace:FindFirstChild("Round")~=nil and game.Workspace.Round.Text == "You have 3 seconds until the match" then
game.Players(_G.myTable[math.random(2,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
end
end)

I don't know. Is my table messed up?

_G.myTable = {}
game.Players.PlayerAdded:connect(function(p)
table.insert(_G.myTable,p.Name)
end)
game.Players.PlayerRemoving:connect(function(r)
for i,v in next, _G.myTable do
if v == r.Name then
table.remove(_G.myTable, i)
break
end
end
end)
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 04:59 PM
Bump..
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 05:23 PM
Guess what? Guess what? Bump says the ring tone.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 06:01 PM
Bumpity bump, look at that frosty go!
Report Abuse
Kizran is not online. Kizran
Joined: 01 Jan 2012
Total Posts: 33
02 Jan 2012 06:09 PM
What are we looking for? Is it not executing? Not doing something correctally?
Report Abuse
YourNeverSafe is not online. YourNeverSafe
Joined: 30 Dec 2011
Total Posts: 462
02 Jan 2012 06:19 PM
_G.myTable = {}
game.Players.PlayerAdded:connect(function(p)
table.insert(_G.myTable,p.Name)
end)
game.Players.PlayerRemoving:connect(function(r)
for i = 1, #G.myTable do
if v == r.Name then
table.remove(_G.myTable, i)
break
end
end
end)
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
02 Jan 2012 06:22 PM
pcall(function()
if game.Workspace:FindFirstChild("Round")~=nil then
if game.Workspace.Round.Text == "You have 3 seconds until the match" then
game.Players(_G.myTable[math.random(2,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
end
end
end)

You were checking to see if an object exists and indexing a property of it. If the object doesn't exist, this will not run. You need consecutive if statements

Report Abuse
fartymarty02 is not online. fartymarty02
Joined: 29 Jan 2011
Total Posts: 336
02 Jan 2012 06:39 PM
pcall(function()
if game.Workspace:FindFirstChild("Round")~=nil then
if game.Workspace.Round.Text == "You have 3 seconds until the match" then
game.Players(_G.myTable[math.random(2,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
end)
end
end

Try that. Or this:

pcall(function()
if game.Workspace:FindFirstChild("Round")~=nil then
if game.Workspace.Round.Text == "You have 3 seconds until the match" then
game.Players(_G.myTable[math.random(2,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
end
end)
end
Report Abuse
fartymarty02 is not online. fartymarty02
Joined: 29 Jan 2011
Total Posts: 336
02 Jan 2012 06:40 PM
WAIT

TRY THIS

pcall(function())
if game.Workspace:FindFirstChild("Round")~=nil then
if game.Workspace.Round.Text == "You have 3 seconds until the match" then
game.Players(_G.myTable[math.random(2,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
end
end
end
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 06:44 PM
Which script is wrong :l
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
02 Jan 2012 06:50 PM
This line stands out: "game.Players(_G.myTable[math.random(2,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)"

To index a table, which is what you're doing there, you need to use the '[' and ']' characters which changes that line to this: game.Players[_G.myTable[math.random(2,#_G.myTable)]].Character.Torso.CFrame = CFrame.new(0,0,0)

Additionally, why are you starting the random choice at two instead of one? This means that one of the players will never be chosen until another enters the game.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 07:01 PM
Still doesn't work.

pcall(function()
if game.Workspace:FindFirstChild("Round")~=nil and game.Workspace.Round.Text == "You have 3 seconds until the match." then
game.Players[_G.myTable[math.random(1,#_G.myTable)]].Character.Torso.CFrame = CFrame.new(0,0,0)
game.Players[_G.myTable[math.random(1,#_G.myTable)]].Character.Torso.CFrame = CFrame.new(0,10,0)
end
end)

Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
02 Jan 2012 07:03 PM
Print the pcall, it'll give you the error.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 07:08 PM
if game.Workspace:FindFirstChild("Round")~=nil and game.Workspace.Round.Text == "You have 3 seconds until the match." then
game.Players[_G.myTable[math.random(1,#_G.myTable)]].Character.Torso.CFrame = CFrame.new(0,0,0)
game.Players[_G.myTable[math.random(1,#_G.myTable)]].Character.Torso.CFrame = CFrame.new(0,10,0)
end

Still doesn't work.

And here's the hint script. If you need to know



while wait() do
if game.Players.NumPlayers >=2 then
local h = Instance.new("Hint",Workspace)
h.Name = "Round"
for i = 20,0,-1 do
wait(1)
h.Text = "You have "..i.." seconds until the match."
if h.Text == "You have 0 seconds until the match." then
wait(1)
for j = 60,0,-1 do
wait(1)
h.Text = "You have "..j.." seconds until round is over."
end
wait(10)
if game.Players.NumPlayers <=2 then
h:Destroy()
else
end
end
end
end
end

Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
02 Jan 2012 07:56 PM
I'm telling you, you need to take what I posted earlier into consideration.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 08:51 PM
Still didn't work.
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
02 Jan 2012 09:03 PM
Post what you have right now. All of it
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
02 Jan 2012 09:04 PM
Might want to use xpcall...

Free Fireworks!
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 09:04 PM
Teleport--Doesn't work

while wait() do
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Round" then
if v.Text == "You have 0 seconds until the match." then
game.Players(_G.myTable[math.random(1,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
game.Players(_G.myTable[math.random(1,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,5,0)
end
end
end
end

Player added in table--Not sure if works.
_G.myTable = {}
game.Players.PlayerAdded:connect(function(p)
table.insert(_G.myTable,p.Name)
end)
game.Players.PlayerRemoving:connect(function(r)
for i,v in next, _G.myTable do
if v == r.Name then
table.remove(_G.myTable, i)
break
end
end
end)

Countdown--Works

while wait() do
if game.Players.NumPlayers >=2 then
local h = Instance.new("Hint",Workspace)
h.Name = "Round"
for i = 20,0,-1 do
wait(1)
h.Text = "You have "..i.." seconds until the match."
if h.Text == "You have 0 seconds until the match." then
wait(1)
for j = 60,0,-1 do
wait(1)
h.Text = "You have "..j.." seconds until round is over."
end
wait(10)
if game.Players.NumPlayers <=2 then
h:Destroy()
else
end
end
end
end
end
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
02 Jan 2012 09:14 PM
Try this.

_G.myTable = {}
game.Players.PlayerAdded:connect(function(p)
table.insert(_G.myTable, p.Name)
end)
game.Players.PlayerRemoving:connect(function(r)
for i,v in next, _G.myTable do
if v == r.Name then
table.remove(_G.myTable, i)
break
end
end
end)

while wait() do
if game.Players.NumPlayers >=2 then
local h = Instance.new("Hint",Workspace)
h.Name = "Round"
for i = 20,0,-1 do
wait(1)
h.Text = "You have "..i.." seconds until the match."
game.Players(_G.myTable[math.random(1,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,0,0)
game.Players(_G.myTable[math.random(1,#_G.myTable)]).Character.Torso.CFrame = CFrame.new(0,5,0)
end
wait(1)
for j = 60,0,-1 do
wait(1)
h.Text = "You have "..j.." seconds until round is over."
end
wait(10)
if game.Players.NumPlayers <=2 then
h:Destroy()
end
end
end
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
02 Jan 2012 09:55 PM
Still didn't work!
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
03 Jan 2012 10:08 AM
GAH. No output?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Jan 2012 10:33 AM
I fixed this script already :P

Sorry bout that. Forgot to tell you.
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
03 Jan 2012 10:34 AM
Aha.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Jan 2012 10:35 AM
Yep, sorry for not telling.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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