I made this ko/wo/credits script but when you reset the first time it doesn't count as a wipe ;/
ranknum = 255
game.Players.PlayerAdded:connect(function(plr)
if plr:GetRankInGroup(2629411) >= ranknum then
plr.Chatted:connect(function(msg)
print("Chat loaded")
if msg:sub(1, 8):lower() == ":credit" then
print("part 1")
local plrindex = msg:sub(9):find(" ")
if plrindex then
local subname = (msg:sub(9, 7+plrindex)):lower()
print(subname)
local plrs = {}
if subname == 'me' then
table.insert(plrs, plr)
print'ayyy'
else
for i, v in pairs(game.Players:GetPlayers()) do
if subname == v.Name:sub(1, plrindex-1):lower() then
print'check'
table.insert(plrs, v)
end
end
end
if #plrs == 1 then
print'k'
pcall(function() plrs[1].leaderstats.Credits.Value = tonumber(msg:sub(plrindex+9)) end)
end
end
end
end)
end
end)
local datastore = game:GetService("DataStoreService")
local dd =datastore:GetDataStore("Stats")
function onHumanoidDied(humanoid, player)
local stats = player:findFirstChild("leaderstats")
if stats ~= nil then
local deaths = stats:findFirstChild("Wipeouts")
deaths.Value = deaths.Value + 1
if deaths.Value>10 then
player.TeamColor=BrickColor.new("White")
end
-- do short dance to try and find the killer
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
handleKillCount(humanoid, player)
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
-- returns the player object that killed this humanoid
-- returns nil if the killer is no longer in the game
-- check for kill tag on humanoid - may be more than one - todo: deal with this
local tag = humanoid:findFirstChild("creator")
-- find player with name on tag
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then -- killer still in game
return killer
end
end
return nil
end
function handleKillCount(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if killer ~= nil then
local stats = killer:findFirstChild("leaderstats")
if stats ~= nil then
local kills = stats:findFirstChild("KOs")
if killer ~= player then
kills.Value = kills.Value + 1
else
kills.Value = kills.Value - 1
end
end
end
end
-----------------------------------------------
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local kills = Instance.new("IntValue")
kills.Name = "KOs"
kills.Value = 0
local deaths = Instance.new("IntValue")
deaths.Name = "Wipeouts"
deaths.Value = 0
kills.Parent = stats
deaths.Parent = stats
local creds = Instance.new("IntValue", stats)
creds.Name = "Credits"
dd:UpdateAsync(newPlayer.userId.."Creds", function(old) creds.Value = old or 0 return creds.Value end )
creds.Changed:connect(function() dd:UpdateAsync(newPlayer.userId.."Creds", function(old) return creds.Value end )end)
-- start to listen for new humanoid
newPlayer.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function() onHumanoidDied(char.Humanoid, newPlayer) end)
end)
stats.Parent = newPlayer
end
game.Players.ChildAdded:connect(onPlayerEntered)

1 comment
Too broad, maybe give us the error?