You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to fix the reloading system, Gui does work but the shooting system doesnt work -
What is the issue? Include screenshots / videos if possible!
The video that gun doesnt shoot -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to make different ways to add ammo after reload but none of the ways didnt work
Local script of the gun, this script contains reload system, firing and others
tool = script.Parent
fireRemote = tool:WaitForChild("fireRemote")
reloadRemote = tool:WaitForChild("reloadRemote")
local settings = require(script.Parent.Settings)
playerService = game:GetService("Players")
client = playerService.LocalPlayer
cursor = client:GetMouse()
user_inputService = game:GetService("UserInputService")
runService = game:GetService("RunService")
Mouse_Icon = "rbxasset://textures/GunCursor.png"
Mouse = nil
equipped = false
reloading = false
db = false
enabled = true
local ammo = settings["ammo"]
local mag = settings["mag"]
function fire()
if enabled == false then return end
if ammo > -0 and tool.Parent:FindFirstChild("Humanoid").Health > 0 then
ammo = ammo - 1
if client.PlayerGui:FindFirstChild("AmmoGUI") then
client.PlayerGui.AmmoGUI.Frame.Ammo.Text = ammo.."/"..mag
end
fireRemote:FireServer(cursor.Hit.Position)
end
if ammo == 0 then
enabled = false
tool.Handle.NoAmmo:Play()
end
end
tool.Equipped:Connect(function()
equipped = true
if script.Parent:FindFirstChild("AmmoGUI") then
script.Parent.AmmoGUI.Frame.Ammo.Text = ammo.."/"..mag
script.Parent.AmmoGUI.ToolName.Text = script.Parent.Name
script.Parent.AmmoGUI.Parent = client.PlayerGui
end
end)
tool.Unequipped:Connect(function()
equipped = false
if client.PlayerGui:FindFirstChild("AmmoGUI") then
client.PlayerGui.AmmoGUI.Parent = script.Parent
end
end)
if settings["autofire"] == true then
runService.Stepped:Connect(function()
if user_inputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
if db == false then
db = true
fire()
wait(settings["firerate"])
db = false
end
end
end)
end
user_inputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R and not reloading then reloading = true
if tool.Handle:FindFirstChild("rldsound")then tool.Handle.rldsound:Play() end
if client.PlayerGui:FindFirstChild("AmmoGUI") then
client.PlayerGui.AmmoGUI.Frame.Ammo.Text = "Reloading"
end
tool.Handle.reloadSound:Play()
wait(settings["reloadtime"])
ammo = settings["ammo"]
reloadRemote:FireServer()
if client.PlayerGui:FindFirstChild("AmmoGUI") then
client.PlayerGui.AmmoGUI.Frame.Ammo.Text = "Reloading"
end
mag -= 1
client.PlayerGui.AmmoGUI.Frame.Ammo.Text = ammo.."/"..mag
reloading = false
end
end)
tool.Activated:Connect(fire)
The firing script
tool = script.Parent
firePart = tool:WaitForChild("Hole")
fireRemote = tool:WaitForChild("fireRemote")
reloadRemote = tool:WaitForChild("reloadRemote")
userHumanoid = tool.Parent:FindFirstChild("Humanoid")
local settings = require(tool.Settings)
ammo = settings["ammo"]
mag = settings["mag"]
range = settings["range"]
enabled = true
Debris = game:GetService("Debris")
debrisService = game:GetService("Debris")
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
fireRemote.OnServerEvent:Connect(function(player, position)
local origin = firePart.Position
local direction = (position - origin).Unit*range
local filter = RaycastParams.new()
filter.FilterType = Enum.RaycastFilterType.Exclude
filter.FilterDescendantsInstances = {tool.Parent}
local result = workspace:Raycast(origin, direction, filter)
local intersection = result and result.Position or origin + direction
local distance = (origin - intersection).Magnitude
local bullet = Instance.new("Part")
bullet.BrickColor = BrickColor.new("New Yeller")
bullet.Anchored = true
bullet.CanCollide = false
bullet.Material = Enum.Material.Neon
bullet.Size = Vector3.new(.2,.2,distance)
bullet.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
bullet.Parent = workspace
local fireSoundClone = tool.Shot:Clone()
fireSoundClone.Parent = tool.Handle
fireSoundClone:Play()
if result then
local part = result.Instance
local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
if humanoid then
UntagHumanoid(humanoid)
TagHumanoid(humanoid,player)
humanoid:TakeDamage(settings["damage"])
end
end
debrisService:AddItem(bullet, 0.05)
debrisService:AddItem(fireSoundClone, fireSoundClone.TimeLength)
end)
reloadRemote.OnServerEvent:Connect(function()
ammo = settings["ammo"]
end)
Any of your help i will appreciate it