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: Why doesn't this work?

Previous Thread :: Next Thread 
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:06 PM
function TeleportToLastStage(Player)
local player = game.Players:GetPlayerFromCharacter(Player)
if player ~= nil then
for i,v in pairs(game.Workspace["Stage Bricks"]:GetChildren()) do
local leaderstats = player.leaderstats
if v:FindFirstChild("One") and leaderstats.Stage.Value == "1" then
Player.Torso.CFrame = v.One.Position + Vector3.new(0,3,0)
elseif v:FindFirstChild("Two") and leaderstats.Stage.Value == "2" then
Player.Torso.CFrame = v.Two.Position + Vector3.new(0,3,0)
elseif v:FindFirstChild("Three") and leaderstats.Stage.Value == "3" then
Player.Torso.CFrame = v.Three.Position + Vector3.new(0,3,0)
elseif v:FindFirstChild("Four") and leaderstats.Stage.Value == "4" then
Player.Torso.CFrame = v.Four.Position + Vector3.new(0,3,0)
elseif v:FindFirstChild("Five") and leaderstats.Stage.Value == "5" then
Player.Torso.CFrame = v.Five.Position + Vector3.new(0,3,0)
elseif v:FindFirstChild("Six") and leaderstats.Stage.Value == "6" then
Player.Torso.CFrame = v.Six.Position + Vector3.new(0,3,0)
end
end
end
end

game.Workspace.ChildAdded:connect(TeleportToLastStage)

It's supposed to teleport you to your last stage if you die.
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
14 Sep 2015 11:08 PM
Torso.CFrame = CFrame.new(v.One.Position) + Vector3.new(0,3,0)
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:08 PM
Use Player.Torso.Position instead of Player.Torso.CFrame.
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:10 PM
Other than that it should work?
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:16 PM
Nope, still doesn't work.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:19 PM
Can you give us the output?
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:19 PM
There is NO output. ._.

When I spawned nothing showed up.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:22 PM
Print out leaderstats.Stage.Value in the for loop to see what you're getting.
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:22 PM
Here's the new one.

game.Workspace.ChildAdded:connect(function(Player)
local player = game.Players:GetPlayerFromCharacter(Player)
if player ~= nil then
for i,v in pairs(game.Workspace["Stage Bricks"]:GetChildren()) do
local leaderstats = player.leaderstats
if v:FindFirstChild("One") and leaderstats.Stage.Value == "1" then
Player.Torso.CFrame = CFrame.new(v.One.Position) + Vector3.new(0,3,0)
elseif v:FindFirstChild("Two") and leaderstats.Stage.Value == "2" then
Player.Torso.CFrame = CFrame.new(v.Two.Position) + Vector3.new(0,3,0)
elseif v:FindFirstChild("Three") and leaderstats.Stage.Value == "3" then
Player.Torso.CFrame = CFrame.new(v.Three.Position) + Vector3.new(0,3,0)
elseif v:FindFirstChild("Four") and leaderstats.Stage.Value == "4" then
Player.Torso.CFrame = CFrame.new(v.Four.Position) + Vector3.new(0,3,0)
elseif v:FindFirstChild("Five") and leaderstats.Stage.Value == "5" then
Player.Torso.CFrame = CFrame.new(v.Five.Position) + Vector3.new(0,3,0)
elseif v:FindFirstChild("Six") and leaderstats.Stage.Value == "6" then
Player.Torso.CFrame = CFrame.new(v.Six.Position) + Vector3.new(0,3,0)
end
end
end
end)
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:23 PM
It printed out 6 things..? e.e
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:25 PM
Oh, the 6 parts..
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:25 PM
Is leaderstats.Stage a StringValue, NumberValue, or IntValue? Make sure you're comparing its Value to the correct type of value. You're currently comparing leaderstats.Stage.Value to strings. Maybe try comparing it with numbers instead?
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:25 PM
IntValue
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:26 PM
@Dennis, if you understand what I'm doing, I'm comparing it to the stage number from the stage intvalue.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:26 PM
Do "leaderstats.Stage.Value == 1" instead of "leaderstats.Stage.Value == '1'".
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:28 PM
New script, once again:

game.Workspace.ChildAdded:connect(function(Player)
local player = game.Players:GetPlayerFromCharacter(Player)
if player ~= nil then
for i,v in pairs(game.Workspace["Stage Bricks"]:GetChildren()) do
local leaderstats = player.leaderstats
--One
if v:FindFirstChild("One") and leaderstats.Stage.Value == 1 then
Player.Torso.CFrame = CFrame.new(v.One.Position) + Vector3.new(0,3,0)
--Two
elseif v:FindFirstChild("Two") and leaderstats.Stage.Value == 2 then
Player.Torso.CFrame = CFrame.new(v.Two.Position) + Vector3.new(0,3,0)
--Three
elseif v:FindFirstChild("Three") and leaderstats.Stage.Value == 3 then
Player.Torso.CFrame = CFrame.new(v.Three.Position) + Vector3.new(0,3,0)
--Four
elseif v:FindFirstChild("Four") and leaderstats.Stage.Value == 4 then
Player.Torso.CFrame = CFrame.new(v.Four.Position) + Vector3.new(0,3,0)
--Five
elseif v:FindFirstChild("Five") and leaderstats.Stage.Value == 5 then
Player.Torso.CFrame = CFrame.new(v.Five.Position) + Vector3.new(0,3,0)
--Six
elseif v:FindFirstChild("Six") and leaderstats.Stage.Value == 6 then
Player.Torso.CFrame = CFrame.new(v.Six.Position) + Vector3.new(0,3,0)
end
end
end
end)

It still doesn't work..

Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:32 PM
I don't know what else to do, is there an easier way to do this?
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:37 PM
Wait, so it's supposed to only run when you die?
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:37 PM
When you spawn it's supposed to teleport you to your last stage that you were at.
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:42 PM
New and improved script!

game.Workspace.ChildAdded:connect(function(Player)
local player = game.Players:GetPlayerFromCharacter(Player)
local Torso = player:FindFirstChild("Torso")
-- Stage Bricks
local StageBricks = game.Workspace:FindFirstChild("Stage Bricks")
-- More Variables below
local leaderstats = player:FindFirstChild("leaderstats")
local Stage = leaderstats:FindFirstChild("Stage")
-- Checking
if leaderstats and Stage then
for i,v in pairs(StageBricks:GetChildren()) do
if Stage.Value == 1 then
Torso.Position = CFrame.new(v.One.Position)+Vector3.new(0,3,0)
elseif Stage.Value == 2 then
Torso.Position = CFrame.new(v.Two.Position)+Vector3.new(0,3,0)
elseif Stage.Value == 3 then
Torso.Position = CFrame.new(v.Three.Position)+Vector3.new(0,3,0)
elseif Stage.Value == 4 then
Torso.Position = CFrame.new(v.Four.Position)+Vector3.new(0,3,0)
elseif Stage.Value == 5 then
Torso.Position = CFrame.new(v.Five.Position)+Vector3.new(0,3,0)
elseif Stage.Value == 6 then
Torso.Position = CFrame.new(v.Six.Position)+Vector3.new(0,3,0)
end
end
end
end)
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:43 PM
So when I asked you to print leaderstats.Stage.Value in the for loop, what was the output?
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:45 PM
It found everything, now the output says "One is not a valid member of Part" wtf?
Report Abuse
SurfaceLight is not online. SurfaceLight
Joined: 06 Apr 2014
Total Posts: 7574
14 Sep 2015 11:50 PM
"Workspace.Script:8: attempt to index local 'Torso' (a nil value)"

Now why is that?
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:52 PM
Ohhhh, I think I know the problem now. You were trying to index One/Two/Three/... within children of Workspace["Stage Bricks"]. So you were doing Workspace["Stage Bricks"].RandomChild.One. Get rid of the for loop, and change v.One/v.Two/v.Three/... to StageBricks.One/StageBricks.Two/StageBricks.Three/...
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 11:53 PM
Now you're getting the error with the Torso because you removed your player checking. Now it's running on random parts that don't belong to players.
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