In todays video I show you how to make a death system inside Roblox Studio, How this death system works is it basically it displays how many times a player has died in a Robox game. This type of system is often seen in sword fighting games or first person shooter games showing how many time you have died. 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("2")
local sessionData = {}
function PlayerAdded(player)
local Deaths = Instance.new("NumberValue")
Deaths.Name = "Deaths" -- Change Deaths to whatever your currency is called.
Deaths.Parent = player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
Deaths.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 = {
["Deaths"] = 0, -- Change Deaths 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
Deaths.Value = sessionData[player.UserId].Deaths -- Change Deaths to whatever your currency is
Deaths:GetPropertyChangedSignal("Value"):Connect(function()
sessionData[player.UserId].Deaths = Deaths.Value -- Change Deaths 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(character)
local Humanoid = character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
local Deaths = player.leaderstats:FindFirstChild("Deaths") -- Change Deaths to whatever your leaderstat is called.
if Deaths then
Deaths.Value = Deaths.value + 1 -- You are able to change the amount added here.
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 DEATH SYSTEM | Roblox Studio
Пікірлер: 40