Hello developers, I made a leaderstats but it doesn’t work the way I want it.
Here is the leaderstats script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
I and I have 2 other scripts which gives you coins/kills for killing a player
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Coins.Value = leaderstats.Coins.Value + 15
end
end)
end)
end)
The other one is the same except the stats are for kills
When I play the game it only shows one of the stats on the leaderstats for example:
Why is it in your first script you create coins with as IntValue, but then recreate it with NumberValue? This is redundant and will make it painful to select it.
I would try changing kills to a NumberValue instead.
All you have to do is as I mention, just make your scripts (not the leaderstats one) this:
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Coins.Value = leaderstats.Coins.Value + 15
end
end)
end)
end)
And the second script:
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Kills.Value = leaderstats.Kills.Value + 15
end
end)
end)
end)
Instead of 2 separate scripts , you could simply union them into 1 script -
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Coins.Value += 15
leaderstats.Kills.Value += 15
end
end)
end)
end)