|
| 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 |
|
|
|
| 21 Dec 2012 01:59 PM |
| The script seems to be set correctly, perhaps it's placed wrong? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 21 Dec 2012 03:05 PM |
Are you sure your hierarchy is correct?
- thedestroyer115 |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 21 Dec 2012 03:17 PM |
Ran this again
print(game.Players.Player1:FindFirstChild("leaderstats"))
>leaderstats
Hmmm?
I'm incredibly confused. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 21 Dec 2012 04:27 PM |
Perhaps post the script that makes the leaderstats?
¤ † KMXD† ¤ |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 21 Dec 2012 07:13 PM |
| I put brackets and semicolons on a lot as i also code Java and c++. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|