I’m trying to create a kill streak system for my FPS game. I’m thinking of adding this script, but I’m not sure if it will work?
local playerKillStreak = {}
game.Players.PlayerKilled.Connect(function(killedPlayer, killerPlayer)
if changedPlayer == killerPlayer then return end
if playerKillStreak[killerPlayer] == nil then
playerKillStreak[killerPlayer] = 1
else
playerKillStreak[killerPlayer] = playerKillStreak[killerPlayer] + 1
end
local currentStreak = playerKillStreak[killerPlayer]
if currentStreak == 3 then
-- Play a sound when the player gets a 3 kill streak
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://123456789" -- Replace with your desired sound ID
sound.Volume = 1
sound.Parent = game.Workspace
sound:Play()
end
if currentStreak == 5 or currentStreak == 10 or currentStreak == 15 or currentStreak == 20 or currentStreak == 25 or currentStreak == 30 then
-- Show a message when the player gets a 5, 10, 15, 20, 25, or 30 kill streak
game.StarterGui:SetCore("ChatMakeSystemMessage"), {
Text = killerPlayer.Name .. " got a " .. tostring(currentStreak) .. " kill streak!",
Color = Color3.fromRGB(255, 165, 0)
})
end
end)
local playerKillStreak = {}
game.Players.PlayerDied:Connect(function(player)
local killer = player.Character.KillerPlayer
if killer == nil then return end
if killer == player then return end
if playerKillStreak[killer] == nil then
playerKillStreak[killer] = 1
else
playerKillStreak[killer] = playerKillStreak[killer] + 1
end
local currentStreak = playerKillStreak[killer]
if currentStreak == 3 then
-- Play a sound when the player gets a 3 kill streak
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://123456789" -- Replace with your desired sound ID
sound.Volume = 1
sound.Parent = game.Workspace
sound:Play()
end
if currentStreak == 5 or currentStreak == 10 or currentStreak == 15 or currentStreak == 20 or currentStreak == 25 or currentStreak == 30 then
-- Show a message when the player gets a 5, 10, 15, 20, 25, or 30 kill streak
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = killer.Name .. " got a " .. tostring(currentStreak) .. " kill streak!",
Color = Color3.fromRGB(255, 165, 0)
})
end
end)
in your code, you should have playeraddedevent and then a characteradded event within essentially so you can always fetch the humanoid from a given character var.
Like I already said, PlayedDied is NOT and event of the player! I think your looking for the .Died event of the humanoid as that is how you can detect if someone dies.
I would recommend if your confused checking out some posts on the Forum because there are lots of posts showing how to use the event.
Wouldn’t it also be easier to store the kill streak somewhere inside the player’s game object as then you are not loading it onto a table and can easily be retrieved
If this is on a server script (which it should be) I would do:
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
--do all stuff you need here
local KillStreak = Instance.new("IntValue",player --or a specific folder)
KillStreak.Name = "KillStreak" --optional name change it to whatever you want
player.CharacterAdded:Connect(function(Char)
Char.Humanoid.Died:Connect(function()
local killer = Char:FindFirstChild("KillerPlayer") --Assuming this is either a string value
if killer == nil then return end
if killer.Value == nil then return end
local Killer = Players[killer.Name]
local PlayerKillS = Killer.KillStreak
PlayerKillS.Value += 1
if PlayerKillS.Value == 3 then
-- Play a sound when the player gets a 3 kill streak
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://123456789" -- Replace with your desired sound ID
sound.Volume = 1
sound.Parent = game.Workspace
sound:Play()
end
if PlayerKillS.Value == 5 or PlayerKillS.Value == 10 or PlayerKillS,Value == 15 or PlayerKillS,Value
== 20 or PlayerKillS,Value== 25 or PlayerKillS,Value== 30 then
-- Show a message when the player gets a 5, 10, 15, 20, 25, or 30 kill streak
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = Killer.Name .. " is on a" .. tostring(PlayerKillS,Value) .. " kill streak!",
Color = Color3.fromRGB(255, 165, 0)
})
end
end)
end)
end)
With the Chat message bit that might need to be put in a local script and fired via remote event along with the Sound effect but I’ve just left it as it was before