idk what its even supposta do lol. it still shoots even after i unequip it.
Give me a few minutes to fix it
okay, thank you for helping me though!
First script:
local gun = script.Parent
local gun_sound = game.ReplicatedStorage["Gun shot"]
local empty_sound = game.ReplicatedStorage.clip_empty
local reload_sound = game.ReplicatedStorage.Reload
local player = game.Players.LocalPlayer
local clipSize = gun.Ammo.Value
local ammo = gun.Ammo
local shooting = script.Parent.Shooting
local equipped = false
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse Icon
local mouse = game.Players.LocalPlayer:GetMouse()
--Remote Event Setup
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
--Checks if Mouse is clicked
gun.Equipped:Connect(function(mouse)
player.PlayerGui.ScreenGui.Ammo.Visible = true
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
equipped = true
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
while shooting.Value and gun.Ammo.Value > 1 and equipped do
task.wait(.5)
remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
gun_sound:Play()
gun.Ammo.Value -= 1
end
else
empty_sound:Play()
end
end)
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
end)
-- Unequip gun
gun.Unequipped:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Visible = false
equipped = false
end)
--Checks if the letter R is pressed to reload
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R and not shooting.Value then shooting.Value = true
while not shooting.Value do
if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 then
reload_sound:Play()
reload_sound.Ended:Wait()
if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)
gun.Ammo.Value = clipSize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
end
end
task.wait(0.1) -- change this to your liking
end
end
end
end
end)
userInput.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
shooting.Value = false
end
end)
-- Update ammo GUI
ammo.Changed:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
end)
Second script:
mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
script.Parent.Shooting.Value = true
end)
mouse.Button1Up:Connect(function()
script.Parent.Shooting.Value = false
end)
Make sure you add a boolValue called shooting, whichâs relative route to both scripts is script.Parent.shooting
Still doesnât work, the gun doesnât even shoot (there are no errors or warnings in the output)
With no error, one state (shooting.Value, gun.Ammo.Value > 1, equipped) must be false.
print(shooting.Value)
print(gun.Ammo.Value)
print(equipped)
add these lines right after the âif gun.Ammo.Value > 1 thenâ line and let me know their output.
nothing is printed, im literally trying to fix the gun for the last 3 days bruh.
print(gun.Ammo.Value) --To see if this state is True
if gun.Ammo.Value > 0 then
print(shooting.Value)
print(gun.Ammo.Value)
print(equipped)
while shooting.Value and gun.Ammo.Value > 1 and equipped do
--If you still get no output it means gun.Ammo.Value is smaller than 0
okay it started printing stuff but the gun still doesnât shoot.
What did it print out? Lemme know
it printed the shooting value, ammo value, and if its even equipped.
I need the exact value for all 3 prints
false - Client - AutoScript:32
33 - Client - AutoScript:33
true - Client - AutoScript:34
Did you add the second script with the content of
mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
script.Parent.Shooting.Value = true
end)
mouse.Button1Up:Connect(function()
script.Parent.Shooting.Value = false
end)
Yes, i did, its inside a local script thats inside a boolvalue called âShootingâ
The goal is to make the shooting variable True, so whatâs important is to find the variable from that script and set shooting to True.
Please add a print line after the script.Parent.Shooting.Value = true
line so we know if it works.
Yes, it goes through, it prints âvalueâs trueâ when the value is true and valueâs false when its false.
why did you delete the post? u did something wrong?
do i place the remoteevent and the serverscript inside the shooting boolvalue?