[SOLVED MYSELF]How to make a player's screen go white for a bit and then fade away without lagging?
Asked by
6 years ago Edited 6 years ago
[ALREADY SOLVED]
This is the third time I am asking this question since the last two times I asked I didn't get an answer.
I am making a stun system that when the player gets hit by a survivor with a baseball bat, he gets stunned and his screen turns white. It works perfectly, but I am having a big problem involving lag.
I am currently using a GUI with a blank frame with the size set to {0, 1000}, {0, 1000} and when the player gets stunned the GUI gets cloned to the player's PlayerGui, and the stunned player's FPS drops dramatically and I have no idea why.
I wanted to know if there is a way to fix the lag or if there is a different way to do it what doesn't lag.
Script just incase you need it
02 | local players = game:GetService( "Players" ) |
03 | local repStorage = game:GetService( "ReplicatedStorage" ) |
04 | local debris = game:GetService( "Debris" ) |
06 | local remotesFolder = repStorage:WaitForChild( "Remotes" ) |
07 | local GUIsFolder = repStorage:WaitForChild( "GUIs" ) |
09 | local equipmentRemote = remotesFolder:WaitForChild( "EquipmentRemote" ) |
11 | local stunnedGUI = GUIsFolder:WaitForChild( "StunnedGUI" ) |
14 | local function castEquipment(player) |
15 | local wPlayer = workspace:WaitForChild(player.Name) |
17 | if not wPlayer:FindFirstChild( "Survivor" ) then return end |
18 | if wPlayer:FindFirstChild( "CantUseEquipment" ) then return end |
20 | local humanoid = wPlayer:WaitForChild( "Humanoid" ) |
21 | local equipment = wPlayer:WaitForChild( "Equipment" ) |
22 | local equipmentAnimation = wPlayer:WaitForChild( "EquipmentAnimation" ) |
24 | local hitSFX = equipment:WaitForChild( "HitSFX" ) |
25 | local swingSFX = equipment:WaitForChild( "SwingSFX" ) |
29 | local equipmentAnimationTrack = humanoid:LoadAnimation(equipmentAnimation) |
30 | equipmentAnimationTrack:Play() |
32 | local cantUseEquipment = Instance.new( "BoolValue" , wPlayer) |
33 | cantUseEquipment.Name = "CantUseEquipment" |
35 | local isUsingEquipment = Instance.new( "BoolValue" , wPlayer) |
36 | isUsingEquipment.Name = "IsUsingEquipment" |
38 | local stats = wPlayer:WaitForChild( "Stats" ) |
40 | local equipmentSpeed = stats:WaitForChild( "EquipmentSpeed" ) |
41 | local equipmentCoolDown = stats:WaitForChild( "EquipmentCoolDown" ) |
42 | local equipmentFunction = stats:WaitForChild( "EquipmentFunction" ) |
44 | debris:AddItem(cantUseEquipment, equipmentCoolDown.Value) |
45 | debris:AddItem(isUsingEquipment, equipmentSpeed.Value) |
47 | local function castEquipmentFunction(hit) |
48 | if not wPlayer:FindFirstChild( "IsUsingEquipment" ) then return end |
49 | if hit.Parent:FindFirstChild( "IsHitByEquipment" ) then return end |
50 | if hit.Parent:FindFirstChild( "Survivor" ) then return end |
51 | if hit.Parent.Name = = player.Name then return end |
52 | if string.match(hit.Parent.Name, "Dummy" ) then return end |
54 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
57 | if equipmentFunction.Value = = "Stun" then |
58 | humanoid.WalkSpeed = 0 |
60 | local victimStats = hit.Parent:WaitForChild( "Stats" ) |
61 | local victimDefaultWalkSpeed = victimStats:WaitForChild( "DefaultWalkSpeed" ) |
63 | local sVictim = players:WaitForChild(player.Name) |
64 | local sVictimPlayerGUI = sVictim:WaitForChild( "PlayerGui" ) |
66 | local newStunnedGUI = stunnedGUI:Clone() |
67 | stunnedGUI.Parent = sVictimPlayerGUI |
72 | newStunnedGUI.BackgroundTransparency = newStunnedGUI.BackgroundTransparency + (. 01 ) |
76 | humanoid.WalkSpeed = victimDefaultWalkSpeed.Value |
81 | for i, v in pairs (wPlayer:GetChildren()) do |
82 | if v:IsA( "Part" ) or v:IsA( "BasePart" ) or v:IsA( "MeshPart" ) or v:IsA( "UnionOperation" ) then |
83 | v.Touched:Connect(castEquipmentFunction) |
89 | equipmentRemote.OnServerEvent:Connect(castEquipment) |