Basically, in my game I want it to make it so every time you die the screen goes black and says like FAILED and adds one death to the leaderboard. The thing is, I have NO IDEA how to do it. I also want to make the screen a bit darker the entire time you're playing. Can someone help? The only thing I've done so far is put the camera in first person lock.
How to make death counter and make screen black out?
2 answers
Here how you can make a death counter on the leaderboard. Put this script in ServerScriptService.
game.Players.PlayerAdded:Connect(function(player)
-- Detect for leaderstats
local leaderstats
if player:FindFirstChild("leaderstats") then
leaderstats = player.leaderstats
else
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
-- create deaths value
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Parent = leaderstats
-- detect character added.
player.CharacterAdded:Connect(function(char)
-- detect humanoid died.
char.Humanoid.Died:Connect(function()
deaths.Value = deaths.Value + 1 -- add 1 value to values
end)
end)
end)
-- work in progress
Hello!
Here is the "screen blackout" script you are looking for. Please note, you are expected to supply the gui yourself.
--localscript inside the gui inside startergui
local background = script.Parent.Background -- the background that it will fade to black with, can be a textlabel with no text in it
local text = script.Parent.TextLabel -- the "Failed!" textlabel thing
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local ts = game:GetService("TweenService") --tweenservice for smooth animations
local info = TweenInfo.new(3,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out)
local infotext = TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.In)
--change the 3 to whatever time you want it to delay
hum.Died:Wait() --waits for the humanoid to die
local tween = ts:Create(background,info,{BackgroundTransparency = 0})
tween:Play()
tween.Completed:Wait()
wait(0.5)
local tween = ts:Create(text, infotext,{TextTransparency = 0})
tween:Play()
tween.Completed:Wait()
This also doubles as the "screen darker the entire time" because you can set the background gui to something like 0.8 backgroundtransparency.
I hope this helped.
If you have any questions, ask them below!
5 comments
Just a heads up, don't index something in game just use game:GetService because it creates the service if it isn't there already, it's sort of like waitforchild but doesnt yield (game.Players -> game:GetService("Players"))
Oh, really? Thanks for your advice!
RAFA1608 i added a local script to starting gui and then i coped that script in. it didnt seem to work in the test tho
Did it spit any errors?
in the output it said this when the script was supposed to be run 17:56:23.829 Background is not a valid member of ScreenGui "Players.dylindude.PlayerGui.ScreenGui" - Client - LocalScript:2 17:56:23.829 Stack Begin - Studio 17:56:23.829 Script 'Players.dylindude.PlayerGui.ScreenGui.LocalScript', Line 2 - Studio - LocalScript:2 17:56:23.830 Stack End - Studio
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
The death leaderboard worked! I just am curious, how could i make like a gui pop up on death, fade the screen black, have a like TRY AGAIN button and then fade out once its clicked?
You can do that with localscripts. Ill try to work something out. Hold on.
MAD_DENISDAILY2 it says this in output when i run ur fade Players.dylindude.PlayerGui.ScreenGui.background.Script:1: attempt to index nil with 'Character'
Would you like something like when you eyes go like open, close a bit, open, close.