chugmilk
|
  |
| Joined: 28 May 2011 |
| Total Posts: 5756 |
|
|
| 23 Jun 2015 06:03 PM |
The second script will run but the first script returns "-" in game. The value doesn't change on the leaderstats, and I'm using DataStores for both scripts. All the difference is one creates adds "Cookie" intValue and one adds "Milk." Again the first script (Milk) script returns a "-" when the game runs...
Help the scripts are basically exactly the same!
-------- Script 1 -------- ds = game:GetService('DataStoreService'):GetDataStore('Stats')
game.Players.PlayerAdded:connect(function(plr) local ls = Instance.new('Model',plr) ls.Name = 'leaderstats' local m = Instance.new('IntValue',ls) m.Name = 'Milk' local data = ds:GetAsync(plr.userId..'_data') if data then m.Value = data else m.Value = 0 end end)
game.Players.PlayerRemoving:connect(function(plr) local stat = plr.leaderstats.Milk ds:SetAsync(plr.userId..'_data',stat.Value) end)
while wait(1) do for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Milk.Value = Player.leaderstats.Milk.Value +1 end end end -------- Script 2 -------- ds = game:GetService('DataStoreService'):GetDataStore('Stats')
as = game:GetService('DataStoreService'):GetDataStore('Stats')
game.Players.PlayerAdded:connect(function(plr) local ls = Instance.new('Model',plr) ls.Name = 'leaderstats' local m = Instance.new('IntValue',ls) m.Name = 'Cookies' local data = as:GetAsync(plr.userId..'_data') if data then m.Value = data else m.Value = 0 end end)
game.Players.PlayerRemoving:connect(function(plr) local stat = plr.leaderstats.Cookies as:SetAsync(plr.userId..'_data',stat.Value) end)
while wait(1) do for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Cookies.Value = Player.leaderstats.Cookies.Value +1 end end end |
|
|
| Report Abuse |
|
|
chugmilk
|
  |
| Joined: 28 May 2011 |
| Total Posts: 5756 |
|
|
| 23 Jun 2015 06:06 PM |
Here is the output
18:04:58.155 - Milk is not a valid member of Model 18:04:58.156 - Script 'Workspace.Milk', Line 24 18:04:58.157 - Stack End
^^ Can't figure out why? |
|
|
| Report Abuse |
|
|
chugmilk
|
  |
| Joined: 28 May 2011 |
| Total Posts: 5756 |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 23 Jun 2015 06:29 PM |
| Because milk isn't a valid member of the model. Fix your heiarchy |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 23 Jun 2015 06:29 PM |
| leaderstats:WaitForChild("Milk") |
|
|
| Report Abuse |
|
|
chugmilk
|
  |
| Joined: 28 May 2011 |
| Total Posts: 5756 |
|
|
| 23 Jun 2015 06:32 PM |
| @Time it should be though since Milk and Cookies are the parent of leaderstats... |
|
|
| Report Abuse |
|
|
chugmilk
|
  |
| Joined: 28 May 2011 |
| Total Posts: 5756 |
|
|
| 23 Jun 2015 06:33 PM |
| @Time it should be though since Milk and Cookies are both children of leaderstats... |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 23 Jun 2015 06:35 PM |
| You're creating 2 leaderstats. Put them into 1 script. |
|
|
| Report Abuse |
|
|