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: attempt to compare userdata with number

Previous Thread :: Next Thread 
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 01:13 PM
I have a script that picks a player based on a numbervalue in a folder called Stuff, the number value is called weight.

local Pick = 0
local ChosenPlayer = nil

function PickPlayer()
Pick = 0
for _,player in pairs(game.Players:GetChildren()) do
local weight = player.Stuff.Weight
if weight and weight.Value > Pick then
Pick = weight
ChosenPlayer = Pick.Parent.Parent
IncreaseWeights(Pick.Parent.Parent)
end
end
return ChosenPlayer
end

this is how I select the player

local Selected = PickPlayer()

I get the same issue though, attempt to compare userdata with number
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 01:20 PM
Fixed it
Report Abuse
rvox is not online. rvox
Joined: 18 Feb 2011
Total Posts: 5380
12 Feb 2016 01:21 PM
Pick = weight.Value


Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 01:23 PM
yeah saw that, thanks a ton though.
Report Abuse
deaththerapy is not online. deaththerapy
Joined: 13 Apr 2008
Total Posts: 497
12 Feb 2016 01:25 PM
Oh, I would suppose your problem is that line near the middle:


if weight and weight.Value > Pick then
Pick = weight
---- The next time the loop cycles through, it will compare the next player's weight.Value with Pick, which is now the last player's Weight instance, not a number.

So to fix it, change that "Pick = weight" to:

Pick = weight.Value
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