Hey, I am trying to script a kill streak system, but I have encountered multiple issues. I currently have a script that properly increases a leaderstat value for when a player kills another player, but I can’t seem to be able to create a script that resets this value when the player dies.
First script (kill counter) that works
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = stats
plr.CharacterAdded:connect(function(char)
local humanoid
repeat
humanoid = char:FindFirstChild("Humanoid")
wait() until humanoid
humanoid.Died:connect(function()
local tag = humanoid:FindFirstChild("creator")
if tag then
local killer = tag.Value
if killer then
killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
end
end
end)
end)
end)
Second script that is supposed to reset the “kills” value when player dies:
game.Players.PlayerAdded:connect(function(player)
local val = player.leaderstats.Kills
player.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function(hum)
val.Value = 0
end)
end)
end)
I am not sure what I did to the script because at one point it did work, but it no longer functions as intended. In addition to that, neither of these scripts work in any Roblox Server games. In other words, the leader board itself only shows up if I run it on a local server or by clicking the “play” button on studio. When launching the public game or a Team Test, the leader board does not show up. I have these both as Scripts in ServerScriptService, is there something I am doing wrong?
Thanks,
migte