Hello there! How do I make it so it slowly blurs using TweenService when you die and unblurs the same way when you respawn? I know you need to use CharacterAdded and CharacterRemoving somewhere, it’s just everytime I tried it didn’t work.
Here are my 2 scripts I used:
local blur = Instance.new("BlurEffect")
blur.Enabled = true
blur.Parent = game.Lighting
blur.Size = 56
blur.Name = "blur1"
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0)
local Goals = {Size = 0}
local Tween = TweenService:Create(blur, info, Goals)
game:GetService("Players").LocalPlayer.CharacterRemoving:Connect(function()
Tween:Play()
end)
local blur = Instance.new("BlurEffect")
blur.Enabled = true
blur.Parent = game.Lighting
blur.Size = 56
blur.Name = "blur2"
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0)
local Goals = {Size = 56}
local Tween = TweenService:Create(blur, info, Goals)
game:GetService("Players").LocalPlayer.CharacterRemoving:Connect(function()
Tween:Play()
end)
Blur effect can be easily fade in and out by using for loop to change the value of its Size. TweenService is not necessary for this at all.
--Fade blur in
local Blur = workspace.Lighting.Blur
for i = 0, 50, 1 do
Blur.Size = i
wait(0.03)
end
--Fade blur out
for i = 50, -1, -1 do
Blur.Size = i
wait(0.03)
end
A potential way of achieving this is using one LocalScript in StarterPlayerScripts. The following script could be a potential way of going about it, listening for when the Character’s Humanoid dies and blurring the screen, the unblurring it once the player has respawned.
-- create blur
local blur = Instance.new("BlurEffect")
blur.Enabled = true
blur.Size = 0
blur.Name = "blur1"
blur.Parent = game.Lighting
-- tweens
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(2,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0)
local tweenBlur = TweenService:Create(blur, info, {Size = 56})
local tweenUnblur = TweenService:Create(blur, info, {Size = 0})
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
-- main
Character:WaitForChild("Humanoid").Died:Connect(function()
tweenBlur:Play()
end)
LocalPlayer.CharacterAdded:Connect(function()
tweenUnblur:Play()
end)
Then copy and paste the code shown below
in the new local script that you just created.
Code
local players = game:GetService("Players")
local lighting = game:GetService("Lighting")
local tweenService = game:GetService("TweenService")
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local blurEffect = lighting.Blur
local information = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
local properties = {BlurSize = 56, UnblurSize = 0}
humanoid.Died:Connect(function()
tweenService:Create(blurEffect, information, {Size = properties.BlurSize}):Play()
end)
character.ChildAdded:Connect(function()
tweenService:Create(blurEffect, information, {Size = properties.UnblurSize}):Play()
end)