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: Help with a very simple leaderboard script.

Previous Thread :: Next Thread 
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 01:47 PM
This is the script:

local plyr = script.Parent

repeat
wait(.1)
print("ugh")
until plyr:FindFirstChild("leaderstats")

The problem is is that it keeps printing "ugh", when leaderstats is in the the plyr. This script is located just inside an added player (I even checked), and leaderstats is inside of the player as well. Why won't it work?
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
21 Dec 2012 01:59 PM
The script seems to be set correctly, perhaps it's placed wrong?
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 02:55 PM
I don't get any output, that's the thing. So I assume everything is placed correctly.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:05 PM
Are you sure your hierarchy is correct?

- thedestroyer115
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 03:10 PM
Yes, I ran a script in the command bar that used the exact same parenting as this, and it worked perfectly fine; it recognized that leaderstats was there inside of the player. I even double and triple checked the parenting, and checked for no typos. What might be the problem?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:12 PM
Okay, enter Tools/Test/Play Solo, uncheck and recheck disabled on the script. Tell me what the output says.

Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 03:14 PM
Ok. I have been testing it in solo right now, but I'll uncheck and recheck disabled.

For more info:

I typed this into the command bar

print(game.Players.Player1:FindFirstChild("leaderstats"))

>nil

Yet clearly leaderstats is inside of Player1. What is happening?
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 03:16 PM
Disabled the script and enabled it again, got no ouput. I think I have found the problem, but I wonder why it is happening?
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 03:17 PM
Ran this again

print(game.Players.Player1:FindFirstChild("leaderstats"))

>leaderstats

Hmmm?

I'm incredibly confused.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:26 PM
.PlayerAdded is unstable in Tools/Test/Play Solo so it works sometimes, and other times the event won't even fire.

Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 04:24 PM
Yeah, that part is working perfectly fine though...

I can tell the loop runs because it prints "ugh" 10 times a second. Yet FindFirstChild does not seem to detect the leaderstats model, even though it is clearly in the player. This has nothing to do with PlayerAdded, sorry.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
21 Dec 2012 04:27 PM
Perhaps post the script that makes the leaderstats?

¤ † KMXD† ¤
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 04:29 PM
game.Players.PlayerAdded:connect(function(plyr)
local leaderstats = Instance.new("Model", plyr)
leaderstats.Name = "leaderstats"

local height = Instance.new("IntValue", leaderstats)
height.Name = "Height"
height.Value = 0

script.HeightofPlayer:clone().Parent = plyr
end)

HeightofPlayer is this, which goes inside the player.

local plyr = script.Parent

function round(num)
return math.floor(num + .5)
end

function script()

repeat
wait(.1)
print("ugh")
until plyr:FindFirstChild("leaderstats")

repeat
wait(.1)
until plyr.leaderstats:FindFirstChild("Height")
print("ok")

while true do
wait(0.1)
plyr.leaderstats.Height.Value = round(plyr.Character.Head.CFrame.Y)-5
end

end

script()

Help?
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 04:31 PM
Here I'll make it clearer.

game.Players.PlayerAdded:connect(function(plyr)
local leaderstats = Instance.new("Model", plyr)
leaderstats.Name = "leaderstats"

local height = Instance.new("IntValue", leaderstats)
height.Name = "Height"
height.Value = 0

script.HeightofPlayer:clone().Parent = plyr
end)

---------------------------------------

HeightofPlayer script now:

---------------------------------------

HeightofPlayer is this, which goes inside the player.

local plyr = script.Parent

function round(num)
return math.floor(num + .5)
end

function script()

repeat
wait(.1)
print("ugh")
until plyr:FindFirstChild("leaderstats")

repeat
wait(.1)
until plyr.leaderstats:FindFirstChild("Height")
print("ok")

while true do
wait(0.1)
plyr.leaderstats.Height.Value = round(plyr.Character.Head.CFrame.Y)-5
end

end

script()
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 04:55 PM
Help pls.
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 05:40 PM
What on earth is wrong?
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
21 Dec 2012 05:49 PM
Try using this, May still be problems but this is what I noticed by looking over it quickly:

game.Players.PlayerAdded:connect(function(plyr)
local leaderstatsv = Instance.new("Model", plyr) --You can't use this name and use player.leaderstats, messes up the script Fix: rename the expression, I added a 'v' to the end
leaderstatsv.Name = "leaderstats"

local height = Instance.new("IntValue", leaderstatsv)
height.Name = "Height"
height.Value = 0

script.HeightofPlayer:clone().Parent = plyr
end)

---------------------------------------

--HeightofPlayer script now:

---------------------------------------

--HeightofPlayer is this, which goes inside the player.

local plyr = script.Parent

function round(num)
return math.floor(num + .5)
end

function run()

repeat
wait(.1)
print("ugh")
until plyr:FindFirstChild("leaderstats")

repeat
wait(.1)
until plyr.leaderstats:FindFirstChild("Height")
print("ok")

while wait() do --Smarter to use while wait() do, will not freeze the game if there is an error/no wait
wait(0.1)
plyr.leaderstats.Height.Value = round(plyr.Character.Head.Position.Y)-5 --CFrame is used when relocating, might still work for reading but it's always safer to use Position
end

end

run() --Not sure but possibly messing it up as script is referring to itself, and referring to a function, Fix: Rename the function
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 06:03 PM
About the first script, I copied most of it from the wiki :P It does work perfectly fine as leaderstats is simply a local variable.

I renamed the function because I thought of that while testing and it appears that there was some problem with it.

And the CFrame thing works just great. I took it from this (not a free model, one of my own scripts :3) which is a script that says a player's height in a gui. I'll show you it:

wait()

function round(num)
return math.floor(num + .5)
end

local player = game.Players.LocalPlayer
local text = script.Parent.TextLabel
time = 0.2

print(player.Name)
print(text)

while true do
wait(time)
text.Text = ("Height: " .. round(player.Character.Head.CFrame.Y)-5)
end

--Yes, that script works perfectly fine...





It appears that the problem is that FindFirstChild is not working correctly, because leaderstats will never become true, when it clearly exists.
Report Abuse
LUVMARIOLUIGI10000 is not online. LUVMARIOLUIGI10000
Joined: 16 May 2009
Total Posts: 1244
21 Dec 2012 06:04 PM
-- don't see anything wrong. However try this other way:

local plyr = script.Parent
if (not plyr:FindFirstChild("leaderstats") then
repeat wait(.1) print("ugh") until plyr:FindFirstChild("leaderstats")
elseif plyr:FindFirstChild("leaderstats") then
end
end

~LUV, LuaLearners Teacher(+2)~
Report Abuse
LUVMARIOLUIGI10000 is not online. LUVMARIOLUIGI10000
Joined: 16 May 2009
Total Posts: 1244
21 Dec 2012 06:06 PM
Whoops, I forgot to close the first '('

local plyr = script.Parent
if (not plyr:FindFirstChild("leaderstats")) then
repeat wait(.1) print("ugh") until plyr:FindFirstChild("leaderstats")
elseif plyr:FindFirstChild("leaderstats") then
end
end

~LUV, LuaLearners Teacher(+2)~
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 06:37 PM
if statements don't require brackets in Lua. Javascript much? :3

I don't know how checking "if not plyr:FindFirstChild("leaderstats")" first will help, but it is worth a shot. Thanks.
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
21 Dec 2012 07:13 PM
I put brackets and semicolons on a lot as i also code Java and c++.
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
21 Dec 2012 07:38 PM
That's nice, but Lua pretty much ignores them if they are not needed. I tested LUVMARIO's way and that did not work either. Help please?
Report Abuse
LUVMARIOLUIGI10000 is not online. LUVMARIOLUIGI10000
Joined: 16 May 2009
Total Posts: 1244
21 Dec 2012 08:10 PM
Well first it checks if there is something called 'leaderstats' in the player. I know the code I gave wasn't great, but I saw no errors; it was just an idea. Also, there are a many ways to do this, but I just went with this because it was the code you gave.

~LUV, LuaLearners Teacher(+2)~
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
22 Dec 2012 07:03 AM
Yeah. I really don't understand the problem as leaderstats is clearly in the player. I'm thinking of using GetChildren do get all of the children in the player, and check if one is leaderstats. If not, it repeats.

Just one question, is it possible to call a function inside of itself? In a way I'm trying to do something like MoveTo, so if you reach a certain condition it goes back to the beginning of the function. Is this possible?
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