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: People Leave -> Game Breaks

Previous Thread :: Next Thread 
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 03:12 PM
I'm having an issue where whenever someone leaves it tries to check for how many players are playing, and breaks because it is trying to find a value that no longer exists.

I'd be happy to explain more if I really could, but I'll be honest when I say I'm completely lost at how to fix it or explain it really.


As much background as I can give:
- It's a racing game.
- When drivers are "in the race" they have a value in their Character Model called "Playing."
- Playing is a Bool Value.
- When set to true, the player is on the racetrack.
- When set to false, the player is in the lobby.
- If there are no drivers with a true "Playing" value the race ends and intermission begins.
- The game checks for how many true values there are every second.

- If someone leaves mid-race the error code is:
Workspace.Track.RaceManager:32: attempt to index field 'Character' (a nil value)
Stack Begin
Script 'Workspace.Track.RaceManager', Line 32
Stack End

In Workspace.Track.RaceManager the problem area in question is:

repeat
for i,v in pairs(playing) do
if v.Character.Playing.Value == true then
print("Still playing")
else
numplaying = numplaying - 1
table.remove(playing, i)
end
end
end
wait(1)
until game.Workspace.Status.Value == "Finishing"


Any help would be greatly appreciated. Thanks.


Report Abuse
WildGuest is not online. WildGuest
Joined: 28 Feb 2010
Total Posts: 647
14 Mar 2017 03:22 PM
repeat
for i,v in pairs(playing) do
if v:FindFirstChild("Character") ~= nil then
if v.Character.Playing.Value == true then
print("Still playing")
else
numplaying = numplaying - 1
table.remove(playing, i)
end
else
numplaying = numplaying - 1
table.remove(playing, i)
end
end
end
wait(1)
until game.Workspace.Status.Value == "Finishing"


Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
14 Mar 2017 03:26 PM
Also, you never change the status value to finishing


||THEBAYOU|| - Almost famous dude
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 03:31 PM
There are some other conditions that cause a status change to go to finish. That's just there, from my understanding, as a fall back plan if something goes wrong. There is stuff between
end
-
end
(until....)

It's not very important though so I didn't include it.


Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
14 Mar 2017 03:32 PM
waiiit so you're nesting until loops?


||THEBAYOU|| - Almost famous dude
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 03:37 PM
Um... Unsure?
I didn't create this piece exactly. I had it commissioned from a friend.


Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
14 Mar 2017 03:38 PM
Ask your friend. XD


||THEBAYOU|| - Almost famous dude
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 03:56 PM
Wildguest's fix doesn't bode well for me.
Numplaying pretty much immediately sets to 0 and ends the race.


Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
14 Mar 2017 03:58 PM
duh... is nobody playing?


||THEBAYOU|| - Almost famous dude
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 04:03 PM
This is what I now have. The problem here is that his fix just immediately sends numplaying (no matter what it starts at) down by 1 every second (because the script checks every second) and therefore numplaying == 0 even if though me and a friend were both on track with true "Playing" values.

repeat
for i,v in pairs(playing) do
if v:FindFirstChild("Character") ~= nil then
if v.Character.Playing.Value == true then
print("Still playing")
else
numplaying = numplaying - 1
table.remove(playing, i)
print("Number Players:")
print(numplaying)
end
else
numplaying = numplaying - 1
table.remove(playing, i)
print("New Number Players:")
print(numplaying)
end
end
if numplaying <= 0 then
game.Workspace.Status.Value = "Finishing"
end
wait(1)
until game.Workspace.Status.Value == "Finishing"


Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
14 Mar 2017 04:09 PM
is playing (the var getting iterated over constantly updated? (when a new player comes, it gets updated))


||THEBAYOU|| - Almost famous dude
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 04:23 PM
Every time a character spawns they get the Playing Value along with other values added to their Character Model. Playing is set to False by default, however is set to True when they come in contact with the car they are driving. (So, with this, when a Character is on track, their Playing value is set to true. However, if they respawn (when they finish the race they get respawned automatically) their Playing value will now be false.) Once 50% of the drivers or (if there is 3 or less drivers that started the race, once everyone has finished) the game realizes the numplaying hit a value too low to continue and the race will finish off.

The problem is that when someone leaves the game mid-race, it breaks down because it looks for a value and can no longer find it because it fails to exist.


Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 04:30 PM
Maybe this might explain more if I add some of the areas it all gets defined?
This is the last working iteration of it. (Before the fix suggested above.)

playing = {}
-----------------------------
local players = game.Players:GetPlayers()
for i = 1, #players do
if players[i].Character.Playing then
table.insert(playing, players[i])
end
numplaying = #playing
starters = #playing
end

for i,v in pairs(game.Players:GetChildren()) do
if v.Character:FindFirstChild("Playing") then
local gui = game.ServerStorage.GUIs.Countdown_GoGUI:clone()
gui.Parent = v.PlayerGui
end
end

repeat
for i,v in pairs(playing) do
if v.Character.Playing.Value == true then
print("Still playing")
else
numplaying = numplaying - 1
table.remove(playing, i)
end
end
if starters >= 6 and numplaying <= 3 then
wait(20)
game.Workspace.Status.Value = "Finishing"
elseif starters == 5 and numplaying <= 2 then
wait(20)
game.Workspace.Status.Value = "Finishing"
elseif starters == 4 and numplaying <= 1 then
wait(20)
game.Workspace.Status.Value = "Finishing"
elseif numplaying <= 0 then
game.Workspace.Status.Value = "Finishing"
end
wait(1)
until game.Workspace.Status.Value == "Finishing"


Report Abuse
Snowskateer is not online. Snowskateer
Joined: 06 Dec 2011
Total Posts: 4647
14 Mar 2017 04:35 PM
wouldnt you connect a playerremoved and then remove that player from participants? would probably stop game from breaking.
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 04:46 PM
I have no clue what you're talking about.


Report Abuse
Snowskateer is not online. Snowskateer
Joined: 06 Dec 2011
Total Posts: 4647
14 Mar 2017 04:47 PM
players.PlayerRemoved:connect(function(plr)
table.remove(playing,plr.Name)
end)
Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 05:19 PM
attempt to index field 'PlayerRemoved' (a nil value)

So, that'd be a no go.


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
14 Mar 2017 05:27 PM
table.remove() takes an index as an argument, not a value.


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
14 Mar 2017 05:28 PM
well you know what I mean


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
14 Mar 2017 05:31 PM
OP, just add a check for the character so it won't error if it's nonexistent.


Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 05:32 PM
See, Lua isn't my exact deal. How would I do such a check for this?


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
14 Mar 2017 05:33 PM
if v.Character and v.Character.Playing.Value then end


Report Abuse
GeorgeTolsmaIII is not online. GeorgeTolsmaIII
Joined: 10 Feb 2011
Total Posts: 700
14 Mar 2017 05:43 PM
Yep.
That did the trick! Thanks so much!


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