I'm making a gun, and when I reload it's supposed to make the interger "Ammo" equal to "MaxAmmo" (Value-wise). However, it does not equal to it. Any help?
Local Script:
local Player = game:GetService("Players").LocalPlayer local Character = Player.Character local Mouse = Player:GetMouse() local Tool = script.Parent local Reload = Tool:WaitForChild("Reload") local Shoot = Tool:WaitForChild("Shoot") local IsEquipped = false local IsReloading = false local IsShooting = false local Damage = 25 local FiringRate = 1.5 local Accuracy = 0.5 local Ammo = Tool:WaitForChild("Ammo") local MaxAmmo = Tool:WaitForChild("MaxAmmo") local Gunshot = Tool:WaitForChild("Gunshot") Tool.Equipped:Connect(function() IsEquipped = true end) Tool.Unequipped:Connect(function() IsEquipped = false end) Tool.Activated:Connect(function() if not IsShooting and Ammo.Value > 0 and not IsReloading then IsShooting = true Fire() wait(FiringRate) IsShooting = false end end) function Fire() local ray = Ray.new(Tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p + Vector3.new(math.random(0-Accuracy,Accuracy),math.random(0-Accuracy,Accuracy),0)).unit * 300) local Part, Position = workspace:FindPartOnRay(ray, Player.Character, false, true) Shoot:FireServer(Tool,Position,Part,Damage) Ammo.Value = Ammo.Value - 1 Gunshot:Play() print("Ammo: "..Ammo.Value.."") end function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then Reload:FireServer() IsReloading = true wait(1.018) IsReloading = false end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Server-Sided Script:
local Tool = script.Parent local Reload = Tool:WaitForChild("Reload") local Shoot = Tool:WaitForChild("Shoot") Reload.OnServerEvent:Connect(function() Tool.ReloadGun:Play() wait(1.018) Tool:WaitForChild("Ammo").Value = Tool:WaitForChild("MaxAmmo").Value print("Ammo: "..Tool:WaitForChild("Ammo").Value.."") end) Shoot.OnServerEvent:Connect(function(Player,Tool,Position,Part,Damage) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Medium stone grey") beam.Material = "Metal" beam.Transparency = 0.25 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (Tool.Handle.CFrame.p - Position).magnitude beam.Size = Vector3.new(0.3, 0.3, distance) beam.CFrame = CFrame.new(Tool.Handle.CFrame.p, Position) * CFrame.new(0, 0, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) if Part then local humanoid = Part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = Part.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then humanoid:TakeDamage(Damage) end end end)
Edit: There are no errors.