Basically, the damage first of all only works some of the time on the gun.
Secondly, the gui is EXTREMELY buggy
Sometimes it works, but sometimes it just glitches out.
I’m extremely confused as I’ve coded it the way it’s intended to be coded, but it just doesn’t work.
Here are the scripts, I just need to fix the weird irregularity and bugginess of this.
Serverscript
Script:
local replicatedstorage = game:GetService("ReplicatedStorage")
local rt = replicatedstorage:WaitForChild("Shoot")
local serverscriptserver = game:GetService("ServerScriptService")
local module = require(serverscriptserver.DamageModule)
local soundservice = game:GetService("SoundService")
local sound = soundservice["Gun Shot"]
rt.OnServerEvent:Connect(function(plr, mouse, tool,pos, targetfilter, ishooting)
local muzzle = tool.Effect.MuzzleEffect
--- print(targetfilter)
targetfilter = tool.Handle
module.IdentifyGun(tool.Name, mouse, muzzle, plr.Name, sound, plr)
end)
Module
Module:
local damage = {}
local config
function damage.IdentifyGun(gunname, target, muzzleeffect, plr, gunshot, player)
local character = player.Character or player.CharacterAdded:Wait()
config = script.Configuration
local folder = config:FindFirstChild(gunname)
local damagevar = folder.Damage
local ammovar = folder.Ammo
local counter = 0
local ammo = character:FindFirstChild(gunname .. " ammo")
if ammo == nil then return end
local debounce = character:FindFirstChild(gunname .. " debounce")
local fireratevar = folder.FireRate
local reloadtimevar = folder.ReloadTime
local maxammovar = folder.MaxAmmo
if target == nil then
return
end
if ammo.Value > 0 and debounce.Value == false then
ammo.Value -=1
debounce.Value = true
muzzleeffect.Enabled = true
gunshot:Play()
task.wait(fireratevar.Value)
debounce.Value = false
muzzleeffect.Enabled = false
if target.Parent:FindFirstChild("Humanoid") then
target.Parent.Humanoid:TakeDamage(damagevar.Value)
end
if ammo.Value == 0 then
debounce.Value = true
task.wait(reloadtimevar.Value)
ammo.Value = maxammovar.Value
debounce.Value = false
return
end
end
end
return damage
Local script
Script:
local remaining = game.ReplicatedStorage.Remaining
local reloadrt = game.ReplicatedStorage.Reload
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local plr = game:GetService("Players").LocalPlayer
local tool = script.Parent
local playergui = plr.PlayerGui
local firerate = 0.4
local debouncereload = false
local uis = game:GetService("UserInputService")
local is_shooting = false
local debounce = false
local maxammo = 26
local amount = 0
local value = plr.Bulletpack.Bullet
local character = plr.Character or plr.CharacterAdded:Wait()
local ammo_out = false
local rt = game.ReplicatedStorage:FindFirstChild("Shoot")
local yield = 0.1
local ammo = 26
local gui = plr.PlayerGui:WaitForChild("GUIGLOCK")
uis.InputBegan:Connect(function(input, fals)
if input.UserInputType == Enum.UserInputType.MouseButton1 and plr.Character:FindFirstChild(script.Parent.Name) then
is_shooting = true
while is_shooting == true and debounce == false do
if ammo <= 0 then
gui.Display.Value.Text = "Reloading"
debounce = true
task.wait(2)
debounce = false
ammo = maxammo
end
ammo -= 1
gui.Display.Value.Text = ammo .. "/".. maxammo
task.wait(yield)
rt:FireServer(mouse.Target,script.Parent,mouse.Hit.Position, mouse.TargetFilter, is_shooting)
end
end
end)
uis.InputEnded:Connect(function(input, fals)
if input.UserInputType == Enum.UserInputType.MouseButton1 and plr.Character:FindFirstChild(script.Parent.Name) then
is_shooting = false
end
end)
tool.Equipped:Connect(function()
gui.Enabled = true
end)
tool.Unequipped:Connect(function()
gui.Enabled = false
end)
Two key problems, the gui and the damage sometimes not registering, how do I fix BOTH of them?
repost as the other post wasn’t getting replies