Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How come this KDR doesn't work?

Asked by
Rapaco 0
10 years ago

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
0
Rapaco, please post your script INSIDE the Code Block. Please edit your question, select all of the script, and hit the button that looks like the Lua logo, and says "Code Block" when you hover over it. AmericanStripes 610 — 10y
0
Got it sorry! Rapaco 0 — 10y

3 answers

Log in to vote
0
Answered by
Gamenew09 180
10 years ago

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

0
Ok will it shows kills and deaths, but what i did is insert the script in scriptservice, and then I got a screen gui and placed it on the gui section, after that I added a textlabel, and I added the localscript, inside the textlabel, and therefore it doesnt show the KDR in the gui? Rapaco 0 — 10y
0
Change the TL variable to script.Parent since you put the LocalScript inside of the TextLabel. Gamenew09 180 — 10y
Ad
Log in to vote
0
Answered by
jacobwow 140
10 years ago

On line 5 script 1 it says

local Kills = Instanc.e.new("IntValue", LS)

It should be

local Kills = Instance.new("IntValue", LS)
0
It doesnt work ._. its shows in the leaderboard "Value", but thats its it doesnt show anything in the gui when you kill someone... Rapaco 0 — 10y
Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
10 years ago
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.

Answer this question