So I am making a FPS framework and I want a dynamic crosshair like in the FE gun kit, when you shoot it expands (ironically the kit I am completely plagiarizing of off because I have no idea how to code that…).
But the thing is, when I aim into the ironsights, the crosshair goes invisible, which is what i want, but when I un-aim, it expands incorrectly, shown in the video below.
This is my code, hopefully it’s self explanatory without showing all of it:
-- Functions:
-- Adjusts the general scale of the crosshair
local function SetCrossCcale(Scale)
CrossScale.t = Scale
end
-- Adjusts the position and transparency (to look good when aiming primarily)
local function RenderCrosshair()
local Size = CrossSpring.p * 4 * CrossScale.p
for i = 1, 4 do
CrossParts[i].BackgroundTransparency = 1 - Size / 20
end
CrossParts[1].Position = UDim2.new(0, Size, 0, 0)
CrossParts[2].Position = UDim2.new(0, -Size - 7, 0, 0)
CrossParts[3].Position = UDim2.new(0, 0, 0, Size)
CrossParts[4].Position = UDim2.new(0, 0, 0, -Size - 7)
end
-- Setting some spring settings
local function SetCrossSettings(Size, Speed, Damper)
CrossSpring.t = Size
CrossSpring.s = Speed
CrossSpring.d = Damper
end
-- What runs when the mouse.Button2Down signal is fired:
SetCrossCcale(GunModule.crosshairaimsize)
-- What runs when the mouse.Button2Up signal is fired:
SetCrossCcale(GunModule.crosshairdefaultsize)
-- What runs when you shoot the gun:
if aiming == false then
CrossSpring:Accelerate(gunset.crosshairexpansion)
else
CrossSpring:Accelerate(gunset.crosshairaimexpansion)
end
-- What runs when the gun is equipped:
SetCrossSettings(gunset.crosshairdefaultsize, 15, 0.8)
-- What runs on RunService.RenderStepped:
RenderCrosshair()
-- And finally, basically all the springs and the CrossParts table:
local CrossSpring = require(game.ReplicatedStorage:WaitForChild('Modules'):WaitForChild('Spring')).spring.new(0)
CrossSpring.s = 12
CrossSpring.d = 0.65
local CrossScale = require(game.ReplicatedStorage:WaitForChild('Modules'):WaitForChild('Spring')).spring.new(0)
CrossScale.s = 10
CrossScale.d = 0.8
CrossScale.t = 1
local CrossParts = {
hud:WaitForChild('Crosshair'):WaitForChild('Main'):WaitForChild('HL'),
hud:WaitForChild('Crosshair'):WaitForChild('Main'):WaitForChild('HR'),
hud:WaitForChild('Crosshair'):WaitForChild('Main'):WaitForChild('VD'),
hud:WaitForChild('Crosshair'):WaitForChild('Main'):WaitForChild('VU'),
}
What happens (the missing horizontal arrows are not the problem, thats a OBS issue I think):
My crosshair GUI:
https://www.roblox.com/library/8591534788/HUD
This is the spring module I used:
https://www.roblox.com/library/8591523093/Spring
No errors, no warnings, no nothing. I’m completely stuck on this one.
Considering my format and my explanation, you will probably get stuck with this question too…