|
| 24 Aug 2013 02:52 PM |
Having issues on online mode, but when I comment out what I need (DataPersistence items), it works in Solo.
Hierarchy:
DataModel -- Workspace ---- PlayerHandler (Script)
-- StarterGui ---- Main (ScreenGui) ------ Stats (Frame) -------- StatsHandler (LocalScript) -------- Kills (TextLabel) -------- Deaths (TextLabel) -------- Kill/Death Ratio (Text Label)
-- PlayerHandler game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady(); if (not player:FindFirstChild('statistics')) then while true do player.ChildAdded:wait(); if (player:FindFirstChild('statistics')) then break; end; end; end; player.CharacterAdded:connect(function(character) local Humanoid = character:FindFirstChild('Humanoid'); if (not Humanoid) then while true do character.ChildAdded:wait(); if (player:FindFirstChild('statistics')) then break; end; end; end; Humanoid.Died:connect(function() local KillTag = character:FindFirstChild('KillTag'); if (KillTag) then local killer = KillTag.Value; if (killer) then killer.statistics.Kills.Value = killer.statistics.Kills.Value + 1; end; end; player.statistics.Deaths.Value = player.statistics.Deaths.Value + 1; end); end); end);
-- StatsHandler player = game.Players.LocalPlayer;
player:WaitForDataReady(); player:LoadInstance('statistics'); statistics = player:FindFirstChild('statistics');
if (not statistics) then statistics = Instance.new('Model', player); statistics.Name = 'statistics'; Instance.new('IntValue', player.statistics).Name = 'Kills'; Instance.new('IntValue', player.statistics).Name = 'Deaths'; end;
for _, s in pairs(statistics:GetChildren()) do s.Changed:connect(function() script.Parent:FindFirstChild(s.Name).Text = s.Name .. ": " .. s.Value; script.Parent['Kill/Death Ratio'].Text = "K/D Ratio: " .. statistics.Kills.Value / statistics.Deaths.Value; player:SaveInstance('statistics', statistics); end); script.Parent:FindFirstChild(s.Name).Text = s.Name .. ": " .. s.Value; end;
if (statistics.Kills.Value > 0 and statistics.Deaths.Value == 0) then script.Parent['Kill/Death Ratio'].Text = "K/D Ratio: " .. statistics.Kills.Value; elseif (statistics.Kills.Value > 0 and statistics.Deaths.Value > 0) then script.Parent['Kill/Death Ratio'].Text = "K/D Ratio: " .. statistics.Kills.Value / statistics.Deaths.Value; else script.Parent['Kill/Death Ratio'].Text = "K/D Ratio: 0"; end; |
|
|
| Report Abuse |
|