In todays video I show you how to make a kill system inside Roblox Studio, How this kill system works is it basically it displays how many times a player has killed other players. This type of system is often seen in sword fighting games or first person shooter games showing how many kills a player has done. Please do keep in mind this is inside a Roblox game and is only based in a Roblox game. So..... if you did want this type of feature in your game make sure to watch to the end of the video to find out how!
I really enjoy making these videos for you all so I hope you enjoy them just as much as I do!
Have a lovely rest of your day!
Script 1:
Option 1: (No DataSaving)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Kills = Instance.new("IntValue")
Kills.Name = "Text Here" -- Change this to what you want the leaderstat name to be
Kills.Value = 0
Kills.Parent = leaderstats
end)
-------------------------------------
Option 2: (DataSaving
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local DatastoreService = game:GetService("DataStoreService")
local Data = DatastoreService:GetDataStore("1")
local sessionData = {}
function PlayerAdded(player)
local Kills = Instance.new("NumberValue")
Kills.Name = "Kills" -- Change Coins to whatever your currency is called.
Kills.Parent = player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
Kills.Parent = leaderstats
local success, playerData = pcall(function()
return Data:GetAsync(player.UserId)
end)
if success then
print("Data loaded: " .. player.Name)
if not playerData then
print("New player, giving default data")
playerData = {
["Kills"] = 0, -- Change Coins to whatever your currency is called.
}
end
sessionData[player.UserId] = playerData
else
warn("Couldn't load data: " .. player.Name)
player:Kick("Couldn't load your data, rejoin")
end
Kills.Value = sessionData[player.UserId].Kills -- Change Coins to whatever your currency is
Kills:GetPropertyChangedSignal("Value"):Connect(function()
sessionData[player.UserId].Kills = Kills.Value -- Change Coins to whatever your currency is
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
function PlayerLeaving(player)
if sessionData[player.UserId] then
local success, errorMsg = pcall(function()
Data:SetAsync(player.UserId, sessionData[player.UserId])
end)
if success then
print("Data saved: " .. player.Name)
else
-- If data saving fails, print a warning
warn("Can't save: " .. player.Name)
end
end
end
Players.PlayerRemoving:Connect(PlayerLeaving)
function ServerShutdown()
if RunService:IsStudio() then
return
end
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(function()
PlayerLeaving(player)
end)
end
end
game:BindToClose(ServerShutdown)
--------------------------------------
Script 2 : (Main Script which gives the leaderstat)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local Humanoid = player.Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
local DamageDealer = Humanoid:FindFirstChild("creator")
if DamageDealer and DamageDealer.Value then
local Killer = game.Players:FindFirstChild(DamageDealer.Value.Name)
if Killer and Killer.leaderstats then
local kills = Killer.leaderstats:FindFirstChild("Kills") -- Change kills to whatever your leaderstat will be called
if kills then kills.Value = (kills.Value or 0) + 1 -- You can adjust how many leaderstats you want to be added each time here.
end
end
end
end)
end)
end)
-----------------------------
If you are a bit confused what to do, Feel free to create a ticket in my discord server and we can help you out!
NEW! Floppys Obby Game : www.roblox.com/games/14917960...
Floppys Simulator Game: www.roblox.com/games/13963457...
FloppyFish Merch Store: itz-floppyfish.creator-spring...
If you would like to support me even more, Super Thanks and becoming a Member is also another way to show your appreciation!
🌟 Floppys Discord Server: / discord
🌟 Floppys Roblox Game : www.roblox.com/games/11301003...
Roblox Studio Tutorial
Roblox Studio
Studio Tutorials
Негізгі бет Ойындар How to make a KILL SYSTEM | Roblox Studio
Пікірлер: 128