|
| 15 Aug 2011 11:52 PM |
Im trying to learn to make a LB and this is what I have so far
function onPlayerEntered(newplayer)
local stats = Instance.new("IntValue") print("1") stats.Name = "leaderstats"
while true do print("2") if newPlayer.Character ~= nil then break end wait(5) end
stats.Parent = newplayer
local kills = Instance.new("IntValue") kills.Parent = leaderstats kills.Name = "Kills" kills.Value = 0 print("3") end
game.Players.ChildAdded:connect(onPlayerEntered)
But the values arent even showing up inside player and im not getting any output |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 12:00 AM |
function onPlayerEntered(newplayer)
local stats = Instance.new("IntValue") stats.Name = "leaderstats" stats.Parent = newplayer
local kills = Instance.new("IntValue") kills.Parent = stats kills.Name = "Kills" kills.Value = 0 end
game.Players.ChildAdded:connect(onPlayerEntered)
|
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 16 Aug 2011 12:01 AM |
newPlayer.Character..
You defined newplayer.
CAPS SENSITIVE.
Although actually that should error, wonder why it doesn't. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 16 Aug 2011 12:11 AM |
I don't see a reason why it shouldn't.
Remove the while true do loop, there's no reason it needs to exist and I think it's what's causing your problem.
Regardless:
game:GetService("Players").PlayerAdded:connect(function(newPlayer) Instance.new("IntValue", newPlayer).Name = "leaderstats" Instance.new("IntValue", newPlayer.leaderstats).Name = "Kills" end)
game:GetService("Players") is the same as game.Players, but it works if Players is renamed. GetService can be used on any service (services are the objects that are normally directly in game).
PlayerAdded is an event that fires when a Player joins the game, it's better than ChildAdded because ChildAdded could fire anytime something is put in Players.
In my script I didn't name my function, you don't need to name the function if you're going to use it once, when it's defined.
Instance.new() actually has 2 arguments, the class of the object you want to make and the parent you want to give it. In addition, if you don't need to assign the instanced value to a variable then you can set the name immeditally. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 12:23 AM |
I tried everything but it still breaks and gives no output... Does it work for you? |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 12:31 AM |
| @swmaniac Add newPlayer:WaitForDataReady at the beginning of your function and then it might work. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 16 Aug 2011 12:36 AM |
... What?
It's not *using* data persistence. Why would it need to wait for the data? |
|
|
| Report Abuse |
|
|
alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 16 Aug 2011 01:29 AM |
| in the output, does it say "running (scriptnamehere)"? |
|
|
| Report Abuse |
|
|
| |
|
Fredfishy
|
  |
| Joined: 21 Mar 2009 |
| Total Posts: 4197 |
|
|
| 16 Aug 2011 01:45 AM |
You sure you aren't just testing this on Tools>Test>Play Solo? :U |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 02:44 AM |
Thats where I test about everything... but no it wont work online either |
|
|
| Report Abuse |
|
|
| |
|
alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 16 Aug 2011 09:48 AM |
use tools>test>server tools>test>start player
that enables output checking in online mode. changed event is buggy in solo mode, and in online you cant check output, so try that. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 10:41 AM |
| @swmaniac; I have found that it needs a wait() at the beginning of leaderboards for some odd reason, and I have just been using :WaitForDataReady() and it seems to be working. |
|
|
| Report Abuse |
|
|