|
| 16 Feb 2015 03:58 AM |
SORRY FOR THE REPOST. The last one had links and these forums don't allow links sooo....
Hey there, so I've been attempting to fix my dang leader board for many centuries, and I'm actually to the very end.... But I CANNOT figure out this error.
------------------------------------- Leader board script inside Workplace: -------------------------------------
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue") stats.Name = "leaderstats"
local cash = Instance.new("IntValue") cash.Name = "cash" cash.Value = 0
local kills = Instance.new("IntValue") kills.Name = "kills" kills.Value = 0
local deaths = Instance.new("IntValue") deaths.Name = "deaths" deaths.Value = 0 cash.Parent = stats stats.Parent = newPlayer kills.Parent = stats deaths.Parent = stats
while true do if newPlayer.Character ~= nil then break end wait(5) end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end ) newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
stats.Parent = newPlayer
end
function Send_DB_Event_Died(victim, killer) local killername = "unknown" if killer ~= nil then killername = killer.Name end print(victim.Name, " was killed by ", killername)
if shared["deaths"] ~= nil then shared["deaths"](victim, killer) print("Death event sent.") end end
function Send_DB_Event_Kill(killer, victim) print(killer.Name, " killed ", victim.Name) if shared["kills"] ~= nil then shared["kills"](killer, victim) print("Kill event sent.") end end
function onHumanoidDied(humanoid, player) local stats = player:findFirstChild("leaderstats") if stats ~= nil then local deaths = stats:findFirstChild("Deaths") deaths.Value = deaths.Value + 1
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
Send_DB_Event_Died(player, killer) handleKillCount(humanoid, player) end end
function onPlayerRespawn(property, player) if property == "Character" and player.Character ~= nil then local humanoid = player.Character.Humanoid local p = player local h = humanoid humanoid.Died:connect(function() onHumanoidDied(h, p) end ) end end
function getKillerOfHumanoidIfStillInGame(humanoid) local tag = humanoid:findFirstChild("creator") if tag ~= nil then local killer = tag.Value if killer.Parent ~= nil then return killer end end
return nil end
function handleKillCount(humanoid, player) local killer = getKillerOfHumanoidIfStillInGame(humanoid) if killer ~= nil then local stats = killer:findFirstChild("leaderstats") if stats ~= nil then local kills = stats:findFirstChild("Kills") if killer ~= player then kills.Value = kills.Value + 1 else kills.Value = kills.Value - 0 end Send_DB_Event_Kill(killer, player) end end end
game.Players.ChildAdded:connect(onPlayerEntered)
------------------------------- Script inside Leader board GUI: -------------------------------
player = script.Parent.Parent.Parent player:WaitForChild("leaderstats")
function updategame() local players=game.Players:GetChildren() for i,v in pairs(players) do players[v].PlayerGui.Leaderboard[player.Name].Value=player.Name.." "..kills..""..deaths ..""..cash end end
function update() local c = script.Parent:GetChildren() for i = 1,#c do if string.sub(c[i].Name, 1, 11) == "PlayerLabel" then c[i].Visible = false end end for i = 1,#plr do local item = script.Parent:findFirstChild("PlayerLabel" .. tostring(i)) if (item~=nil) then item.Visible = true item.Text = plr[i].Name.." "..kills..""..deaths..""..cash end end end
player.leaderstats.kills.Value.Changed:connect(function (updatestatkill) kills = player.leaderstats.kills.Value updategame() end)
player.leaderstats.deaths.Value.Changed:connect(function (updatestatdeaths) deaths = player.leaderstats.deaths.Value updategame() end)
player.leaderstats.cash.Value.Changed:connect(function (updatestatcash) cash = player.leaderstats.cash.Value updategame() end)
function getNumber(obj) for i = 1,#plr do if plr[i]==obj then return i end end end
plr = {} p = game.Players:GetChildren()
for i = 1,#p do table.insert(plr, p[i]) end
update() game.Players.ChildAdded:connect(function (guy) table.insert(plr, guy) update() end) game.Players.ChildRemoved:connect(function (guy) table.remove(plr, getNumber(guy)) update() end)
---------------------- Error it is producing: ----------------------
00:01:21.965 - Players.Player.PlayerGui.Leaderboard.Script:12: attempt to index field 'Value' (a number value) 00:01:21.965 - Stack Begin 00:01:21.966 - Script 'Players.Player.PlayerGui.Leaderboard.Script', Line 12 00:01:21.966 - Stack End
----------------------------------------------------------------- Some Things I've tried (Cant remember all, I did a ton of stuff): -----------------------------------------------------------------
1. Trying to change IntValue to NumberValue 2. Delaying the Children so the script has time to fully load 3. Different leader board scripts all the same result. 4. Some other misc stuff that I cant remember.
Thanks in Advance! Dan
|
|
|
| Report Abuse |
|
|
| 16 Feb 2015 04:01 AM |
APOLOGIES! I switched up the code a bit before I posted, this is the error:
02:00:17.905 - Players.Player.PlayerGui.Leaderboard.Main:28: attempt to index field 'Value' (a number value) 02:00:17.906 - Stack Begin 02:00:17.906 - Script 'Players.Player.PlayerGui.Leaderboard.Main', Line 28 02:00:17.906 - Stack End
Again, sorry about that. |
|
|
| Report Abuse |
|