I placed this script in the Serverscriptservice.
game.Players.PlayerAdded:connect(function(Player) local LS = Instance.new("IntValue", Player) -- LS = leaderstats LS.Name = "leaderstats" local Kills = Instanc.e.new("IntValue", LS) -- (ClassName, Parent) local Kills = "Kills" local Deaths = Instance.new("IntValue", LS) Deaths.Name = "Deaths" end)
Then I placed this in a localscript in a screen gui and a text label in a screen gui. Does this require a leaderboard in workspace for it to work?
local Player = game.Players.LocalPlayer local Stats = Player.leaderstats local Kills = Stats.Kills local Deaths = Stats.Deaths local KDR = ( Kills.Value / Deaths.Value ) local TL = script.Parent.TextLabel local Team1 = game.Teams.Team1 local Team2 = game.Teams.Team2 while wait() do if Team1.Score > Team2.Score then TL.Text = "K/D: " .. tostring(KDR) .. " Winning Team: "..Team1.Name elseif Team2.Score > Team1.Score then TL.Text = "K/D: " .. tostring(KDR) .. " Winning Team: "..Team2.Name end end
You need to change Instanc.e.new, having kills' name set, and KDR needs to be set everytime the loop is used.
ServerScriptService Script:
game.Players.PlayerAdded:connect(function(Player) local LS = Instance.new("IntValue", Player) -- LS = leaderstats LS.Name = "leaderstats" local Kills = Instance.new("IntValue", LS) -- (ClassName, Parent) -- Instanc.e.new turns into Instance.new Kills.Name = "Kills" -- Should set the name of the Kills IntValue instead of Kills = "Kills" which would set the variable to a string. local Deaths = Instance.new("IntValue", LS) Deaths.Name = "Deaths" end)
LocalScript:
local Player = game.Players.LocalPlayer local Stats = Player.leaderstats local Kills = Stats.Kills local Deaths = Stats.Deaths local KDR = ( Kills.Value / Deaths.Value ) local TL = script.Parent.TextLabel local Team1 = game.Teams.Team1 local Team2 = game.Teams.Team2 while wait() do if Team1.Score > Team2.Score then TL.Text = "K/D: " .. tostring(KDR) .. " Winning Team: "..Team1.Name elseif Team2.Score > Team1.Score then TL.Text = "K/D: " .. tostring(KDR) .. " Winning Team: "..Team2.Name end KDR = ( Kills.Value / Deaths.Value ) -- You need to set KDR each time this loop is used. end
On line 5 script 1 it says
local Kills = Instanc.e.new("IntValue", LS)
It should be
local Kills = Instance.new("IntValue", LS)
game.Players.PlayerAdded:connect(function(Player) local LS = Instance.new("IntValue", Player) -- LS = leaderstats LS.Name = "leaderstats" local Kills = Instanc.e.new("IntValue", LS) -- (ClassName, Parent) local Kills = "Kills" -- This need to be switched local Deaths = Instance.new("IntValue", LS) Deaths.Name = "Deaths" end)
game.Players.PlayerAdded:connect(function(Player) local LS = Instance.new("IntValue", Player) -- LS = leaderstats LS.Name = "leaderstats" local Kills = Instanc.e.new("IntValue", LS) -- (ClassName, Parent) Kills.Name = "Kills" -- Need to fix this. local Deaths = Instance.new("IntValue", LS) Deaths.Name = "Deaths" end)
I believe I fixed it for you.