Hi, so I have made a script that is supposed to make my Crosshair UI responsive to what i do in game. The problem is my script doesnt works all time and is very buggy, so i am wondering how I could improve it and if there is a best way to do that
Code :
local player = game.Players.LocalPlayer
local Backpack = player.Backpack
local Cross = script.Parent.Frame
local Intensity = Instance.new('IntValue', player.Backpack)
Intensity.Name = "Intensity"
Intensity.Value = 0
Intensity.Value = math.clamp(Intensity.Value, 0, 3)
local FireEvent = game.ReplicatedStorage.LocalEvents.Fire
local Aiming = game.ReplicatedStorage.LocalEvents.Aiming
local Map = {
[0] = UDim2.new(0.002, 0,0.005, 0), -- Normal or Aiming
[1] = UDim2.new(0.038, 0,0.086, 0), -- Walking
[2] = UDim2.new(0.102, 0,0.233, 0), -- Running
[3] = UDim2.new(0.276, 0,0.631, 0) -- Shooting
}
player.Character:WaitForChild('Humanoid').Running:Connect(function(speed)
if speed >= 1 and speed <= 16 then
Intensity.Value = 1
elseif speed >= 17 and speed <= 30 then
Intensity.Value = 2
elseif speed == 0 then
Intensity.Value = 0
end
end)
FireEvent.Event:Connect(function(isShooting)
if isShooting then
Intensity.Value += 1
else
Intensity.Value -= 1
end
end)
Aiming.Event:Connect(function(isAiming)
if isAiming then
Intensity.Value -= 1
else
Intensity.Value += 1
end
end)
game["Run Service"].RenderStepped:Connect(function()
if Intensity.Value >= 0 and Intensity.Value <= 3 then
Cross:TweenSize(Map[Intensity.Value], "In", "Linear", 0.05)
end
end)
Thanks !