Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I have a problem with the Blur Effect and the scripting use of it. Could Anyone Help?

Asked by
PolyyDev 214 Moderation Voter
6 years ago

I am trying to use a script for it to clear when you click play and blur again when you die. But it just goes negative and it wont go back up to 0

Script 1:

local player = game.Players.LocalPlayer
local blur = game.Lighting:WaitForChild("Blur")
while true do
    if player.Character.Humanoid.Health <= 0 then
    blur.Enabled = true 
    repeat blur.Size = blur.Size + 0.1 wait(0.01) until blur.Size == 24

    else


    end 

    wait()

end

Script 2:

local frame = script.Parent.Parent
local blur = game.Lighting:WaitForChild("Blur")
local player = game.Players.LocalPlayer
while true do
script.Parent.MouseButton1Click:Connect(function()
    frame:TweenPosition(UDim2.new(-1,0,-0.052,0), "In", "Sine", 1.5)
    wait(0.3)
    repeat blur.Size = blur.Size - 0.1 wait(0.01) until blur.Size == 0
    blur.Enabled = false
    player.Character:MoveTo(Vector3.new(-202, 6.1, 44))
    if blur.Size >= 0 then
        blur.Size = 0
    end

    wait(5)
end)
end

Ask a question in the comments if I missed any details.

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Hey Ki_ngPhantom,

I've figured out the issue in your second script as to why your blur effect doesn't stop at 0. However, there are some enhancements you can definitely make with that script which can improve your script quiet a lot, I will go over those in this answer as well and it's my best advise that you take it.

Issues

Useless if statement and while loop, and Operator Problem

Your first and foremost issue that I saw in your second script was the while loop. In-fact it crashed the game so I had to kill the script and make a new file. Anyways, get rid of that while loop, it's useless in your situation and you forgot to put a wait in there but, the while loop is not needed. The other issue that I found was in your repeat loop. First off, I don't even know why you're using a repeat loop. I'll go over enhancing that loop into a better one later but, for now let's go over why it didn't work quiet as well as you supposed it would. Ok so, your repeat loop checked if the Size is equal to 0 however, by the time it was checking if the size was equal to 0, the size had already changed because of how fast the code went. So, for this I'd advise using <= to operator to check for that. Below is the script assuming that everything else(like the tweening) works fine in your script. Also, I removed that useless if statement you had below the :MoveTo() method.

Issues Fixed Example

local frame = script.Parent.Parent
local blur = game.Lighting:WaitForChild("Blur")
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    frame:TweenPosition(UDim2.new(-1,0,-0.052,0), "In", "Sine", 1.5)
    wait(0.3)
    repeat blur.Size = blur.Size - 0.1 wait(0.01) until blur.Size <= 0
    blur.Enabled = false
    player.Character:MoveTo(Vector3.new(-202, 6.1, 44))

    wait(5)
end)

If you replace your second script with the one above, everything should work just fine however, I'm gonna give you some enhancements to your code and I highly recommend you check this out because it's for both of your scripts.

Enhancements

I made exactly what you wanted to make and then compared your script to mine and that's how my enhancements were established so, most of these examples are done with my coding and they use well-updated and efficient methods.

Script 1: Humanoid Died Event with CharacterAdded, :WaitForChild() and :GetService()

Alright, so you have a while loop running through out the whole game. This can make your game lag and having a loop run at all times is just a terrible idea because it can increase latency in your game. I recommend using the CharacterAdded event to detect when the Character is added and then simply make a variable for the Humanoid and use it's Died event. :WaitForChild() method makes your game anti-StreamingEnabled and you are not making many requests for your game to get certain items rather, you wait for them so your game decreases in lag. :GetService() is good to use because in the future the names of the Services might change and you will not be able to just get them by doing game.Service, so it gives your script a nice foundation and good durability. Below is an enhancement example of this.

Enhancement Example A

local players = game:GetService("Players")
local player = players.LocalPlayer;
local lighting = game:GetService("Lighting");
local blur = lighting:WaitForChild("Blur");

player.CharacterAdded:Connect(function(char)
    local hum = char:WaitForChild("Humanoid");

    hum.Died:Connect(function()
    blur.Enabled = true 
    repeat blur.Size = blur.Size + 0.1 wait(0.01) until blur.Size == 24
    end)
end)

Script 1: For loop instead of repeat loop

For your purposes, I would suggest using a for loop because I believe that not only will it decrease lag but, it will make your script better organized and it's very easy to make as well, at least for your purposes. Below is an enhancement example of this.

Enhancement Example B

local players = game:GetService("Players")
local player = players.LocalPlayer;
local lighting = game:GetService("Lighting");
local blur = lighting:WaitForChild("Blur");

player.CharacterAdded:Connect(function(char)
    local hum = char:WaitForChild("Humanoid");

    hum.Died:Connect(function()
    blur.Enabled = true;
        for i = 0, 24, 0.1 do
            wait(0.01);
            blur.Size = i;
        end
    end)
end)

Script 2: :WaitForChild() and :GetService()

Well, I showed you how to do that above so all you have to do is implement that into this every time you declare a variable. But, I'll show you how to do it just in-case you get stuck. Below is an enhancement example of this.

Enhancement Example C

local frame = script.Parent.Parent;
local lighting = game:GetService("Lighting")
local blur = lighting:WaitForChild("Blur")
local players = game:GetService("Players")
local player = players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    frame:TweenPosition(UDim2.new(-1,0,-0.052,0), "In", "Sine", 1.5)
    wait(0.3)
    repeat blur.Size = blur.Size - 0.1 wait(0.01) until blur.Size <= 0
    blur.Enabled = false
    player.Character:MoveTo(Vector3.new(-202, 6.1, 44))

    wait(5)
end)

Script 2: For loop instead of repeat loop.

I talked about this above as well and from that script up there you should be able to do it here but, I'll provide you with an example just in-case you need it.

Enhancement Example D

local frame = script.Parent.Parent; local lighting = game:GetService("Lighting") local blur = lighting:WaitForChild("Blur") local players = game:GetService("Players") local player = players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function() frame:TweenPosition(UDim2.new(-1,0,-0.052,0), "In", "Sine", 1.5) wait(0.3)

for i = 24, 0, -0.1 do
    wait(0.01)
    blur.Size = i;
end
blur.Enabled = false
player.Character:MoveTo(Vector3.new(-202, 6.1, 44))

wait(5)

end)

Well, that should've covered it all and if it still doesn't work then please comment below.

~~ KingLoneCat

0
I would have used the tween service :P User#5423 17 — 6y
0
I didn't mess with any of his tweening because I don't have the environment he has in his game. KingLoneCat 2642 — 6y
0
How long did it take to write this? AdvancedCode 136 — 6y
0
Like an hour. KingLoneCat 2642 — 6y
Ad
Log in to vote
0
Answered by
Rawblocky 217 Moderation Voter
6 years ago

Please note: I'm not a FE scripter

(SCRIPT #1) First off, you made it so ALL of the players see the blur effect, rather than the player itself. So when someone dies, everyone is going to have a blur effect, even the people who are still alive. To fix this, remove the blur effect in the Lighting, and change the second line to

Iocal blur = Instance.new('BlurEffect',workspace.CurrentCamera)
blur.Enabled = false
blur.Size = 0

Second, when the player respawns, they still see the blur effect. To fix this, you basically clear all of the children in the CurrentCamera. Put this in the first line:

workspace.CurrentCamera:ClearAllChildren()

Instead of waiting until the player dies with While True Do, you can basically use repeat instead. Example:

repeat wait() until  player.Character.Humanoid.Health <= 0

Now, enable the blur effect! The 6th line on your script is very slow on making the blur effect huge, and doesn't have time to get it to 24, because it's very slow. It may hit like about 12 when you respawn, but it doesnt fully blur when you die. To fix this, instead of adding 0.1 to the size, add 0.5!

repeat blur.Size = blur.Size + 0.5 wait(0.01) until blur.Size >= 24

Full edited code:

workspace.CurrentCamera:ClearAllChildren()
local player = game.Players.LocalPlayer
local blur = Instance.new('BlurEffect',workspace.CurrentCamera)
blur.Size = 0
blur.Enabled = false
    repeat wait() until  player.Character.Humanoid.Health <= 0
    blur.Enabled = true 
    repeat blur.Size = blur.Size + 0.5 wait(0.01) until blur.Size >= 24

(SCRIPT 2) I don't get what you mean by "click play and blur again when you die", so please leave a comment here, and I will edit it until I figure out what you're talking about

Answer this question