no errors for StateGunHud when firing server
local Mouse = Player:GetMouse()
local Gun = script.Parent.Parent.Gun
local UserInputService = game:GetService('UserInputService')
local TweenService = game:GetService('TweenService')
local Camera = workspace.CurrentCamera
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Bullets = ReplicatedStorage:WaitForChild('Bullets')
local BulletType = Bullets:WaitForChild('BulletType')
local Events = ReplicatedStorage:WaitForChild('Events')
local RemoteEvents = Events:WaitForChild('RemoteEvents')
local StateGunHud = RemoteEvents:FindFirstChild('StateGunHud')
Gun.GripUp = Vector3.new(0,1,0)
Gun.GripRight = Vector3.new(0,0,1)
local Index = {['ZoomIn'] = 65, ['ZoomOut'] = 75}
local Info = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local function TweenCamera(Properties)
local T = TweenService:Create(game.Workspace.CurrentCamera, Info, Properties)
T:Play()
end
local equipped = false
local function Zoom(key)
if Player and Player.Character then
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType[key] then
if equipped then
local Properties = {FieldOfView = Index.ZoomIn}
TweenCamera(Properties)
wait(0.1)
StateGunHud:FireServer(true)
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType[key] then
if equipped then
local Properties = {FieldOfView = Index.ZoomOut}
TweenCamera(Properties)
wait(0.1)
StateGunHud:FireServer(false)
end
end
end)
end
end
Gun.Equipped:Connect(function()
equipped = true
Zoom('MouseButton2')
Mouse.Icon = 'rbxassetid://61374156'
end)
Gun.Unequipped:Connect(function()
local Properties = {FieldOfView = Index.ZoomOut}
TweenCamera(Properties)
equipped = false
Mouse.Icon = ''
wait(0.1)
StateGunHud:FireServer(false)
end)
To make the gui appear
local Events = ReplicatedStorage:WaitForChild('Events')
local RemoteEvents = Events:WaitForChild('RemoteEvents')
local StateGunHud = RemoteEvents:FindFirstChild('StateGunHud')
local Main = script.Parent.Parent.Parent:WaitForChild('Main')
local GunHudGui = Main:WaitForChild('GunHudGui')
StateGunHud.OnClientEvent:Connect(function(Player, Visibility)
GunHudGui.Visible = Visibility
end)```