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 » Scripting Helpers
Home Search
 

Re: Why does my script stop at 'if' and don't continue?

Previous Thread :: Next Thread 
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 12:50 PM
This is basically what constitutes f. :
~~~~~~~~~~~~~~~~~
for k, f in pairs(Game.Players:GetPlayers()) do coroutine.wrap(function()
~~~~~~~~~~~~~~~~~
**Now this is the PORTION where the trouble begins and where the script doesn't move on:**
~~~~~~~~~~~~~~~~~
GameState = Instance.new("IntValue")
GameState.Parent = f.Backpack
GameState.Name = "GameState"
f.Backpack.GameState.Value = 1

if f.Backpack.GameState.Value == 1 then <----Line 108: It does a check, but if I do not have IntValue GameState in my backpack, the script does not continue.
Game.Lighting.BeginnerSword:Clone().Parent = f.Backpack wait(0.1)
f.Backpack.GameState:Destroy()
end
H = Instance.new("Hint")
H.Parent = game.Workspace
time = 122
Game_Launch_Part_Three()
end)()
t = t + 1 if t > #spawns then t = 1
end
end
wait(.1)
end
~~~~~~~~~~~~~~~~~
This is basically what happens in a nutshell:
To test this script, I go in-game and then I wait a bit for the script to place GameState in my backpack(and it does all of that fine) then I reset to test if the script keeps moving even if the player(s) do not have GameState in their backpack but it doesn't and it stops and gives these errors:
~~~~~~~~~~~~~~~~~
19:36:14.440 - GameState is not a valid member of Backpack
19:36:14.441 - Script 'Workspace.OvEngine(Game Script)', Line 108
19:36:14.442 - Stack End
~~~~~~~~~~~~~~~~~
I want it to continue even if I reset and do not have GameState in my backpack. It does not do that, it stops at 'if' and returns the following error.
You do not need the whole script, I checked the whole script and it is working fine up to the 'if' part. That portion is the only portion that needs fixing.
Question is why and how can I fix it?
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 12:57 PM
Help.
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 01:00 PM
Is it hard?
Report Abuse
Aesthetical is online. Aesthetical
Joined: 01 Jan 2014
Total Posts: 2141
19 Jun 2014 01:03 PM
Maybe the gamestate value isn't equal to one then by the time it runs the if statement?
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 01:05 PM
It actually does, I checked in-studio. But after it checks the 'if' the script completely stops.
Report Abuse
Aesthetical is online. Aesthetical
Joined: 01 Jan 2014
Total Posts: 2141
19 Jun 2014 01:07 PM
Add a

print(f.Backpack.GameState.Value)

right before and after that if statement.
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 01:45 PM
Alright so here's what's happening:
*I do get GameState in my backpack, value is one when I play it in studio.
*I reset to lose the GameState IntValue and then It checks if I have GameState or not.
*If I do not have GameState or if the PLAYER does not have GameState, I want the script to keep going regardless or not he has GameState.

^^Currently if the script finds that a player does not have GameState in his backpack then the script will stop completely. Why is that?
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 01:51 PM
Please help.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 01:52 PM
Do what Aesthetical said.
Tell us what it prints.
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 01:58 PM
@thedestroyer:
Okay, so basically GameState is a member of backpack prior to the check but when I reset, and it checks - the script completely stops.
That's the problem. I want the script to continue even if I do not have GameState.

The print thing is pretty much useless - it works when I do not reset, and flawlessly but I want to have it so whether or not I reset - the script continues and the check would still apply.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 01:59 PM
Give us the output when it works and does not work.

We can figure out the issue.

Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 02:00 PM
Let me try to explain.
X = Player
X goes in the game, and the game starts.
The game gives X an INTVALUE called GameState = 1 and if X resets before the check(it happens after 5 seconds)
then the game continues and does not stop.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 02:01 PM
Check it before the player resets?
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 02:01 PM
When it works: When I do not reset prior to the check and GameState is in my backpack.
When it doesn't work: When I reset and GameState is no longer in my backpack therefore an error "GameState is not a valid member of backpack." but I want it to continue even if I do not have GameState in my backpack.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 02:03 PM
Just check if GameState exists before checking its value.
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 02:07 PM
Okay, nvm. I fixed the problem but yeah...Errr..I'm still curious.
How can I check if gamestate exists? What's the if function for that?
if f.Backpack.GameState = true then? Is that how you check it?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 02:09 PM
if f.Backpack:FindFirstChild("GameState") ~= nil then
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 02:13 PM
Oh there we go. Thanks for that snippet. :3 I have a new curiousity question by the way.
Say I do something like:
p= game.Players:GetChildren()
for i= 1, #p do
Can I do something like this to refer to a specified random player
p[1].Character.Torso.CFrame = CFrame.new(Vector3.new(blcks.Position.x,blcks.Position.y+3,blcks.Position.z))
p[2].Character.Torso.CFrame = CFrame.new(Vector3.new(blcks.Position.x,blcks.Position.y+3,blcks.Position.z))
p[3].Character.Torso.CFrame = CFrame.new(Vector3.new(blcks.Position.x,blcks.Position.y+3,blcks.Position.z))

If I wanted to teleport them to different positions on a map?
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 02:15 PM
Would that work?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 02:17 PM
It'd be easier to put pre-defined positions into a table and randomly select one.

Then you have some control of spawn positions.
Report Abuse
Overpride is not online. Overpride
Joined: 30 Aug 2011
Total Posts: 1037
19 Jun 2014 02:20 PM
Can you show me a script that does that for a demonstration?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
19 Jun 2014 02:25 PM
RandomPositions = {
Vector3.new(0, 0, 0),
Vector3.new(1, 1, 1),
Vector3.new(2, 2, 2)
}

for _, Player in pairs(game.Players:GetPlayers()) do
if Player.Character ~= nil then
Player.Character:MoveTo(RandomPositions[math.random(1, #RandomPositions)])
end
end
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