I was working on this code for a long time and it works but only client side by, the way I have FE on.
wait()
local Tool = script.Parent
local Handle = Tool.Handle
local Barrel = Tool.Barrel
local Player
local Character
local anim = Instance.new("Animation")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Humanoid = player.Character.Humanoid
local AnimationR = Instance.new("Animation")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6682923631"
AnimationR.AnimationId = "rbxassetid://6684441078"
local Anim = Humanoid:LoadAnimation(Animation)
local AnimR = Humanoid:LoadAnimation(AnimationR)
local GoodHit = {245630921, 245630994, 245631056, 252944176, 245631167}
local MissHit = {142082166, 303465115, 303465155, 233091225, 303465215}
local DamageMin = 15
local DamageMax = 20
local Enabled = true
local Reloading = false
local Firing = false
local ReloadTime = 3
local AmmoGui = nil
local Hum
function fireGun(originCF, aimToCF, lengthOfRay)
if Handle:FindFirstChild('Fire') then
Handle.Fire:Play()
end
local DetectionRay = Ray.new(originCF, (aimToCF - originCF).unit * lengthOfRay)
local PartHit, Position, IntersectPoint, MaterialHit = workspace:FindPartOnRay(DetectionRay, Character)
if PartHit then
Hum = PartHit.Parent:FindFirstChild('Humanoid')
if not Hum then
Hum = PartHit.Parent.Parent:FindFirstChild('Humanoid')
end
if Hum then
local count = math.random(DamageMin, DamageMax)
Hum:TakeDamage(count)
end
end
Enabled = false
Barrel.MuzzleFlare.FlareImage.Rotation = math.random(-360, 360)
for _,muzzleinstance in ipairs(Barrel:GetChildren()) do
if string.sub(muzzleinstance.Name, 1, 6) == 'Muzzle' then
muzzleinstance.Enabled = true
Anim:Play()
end
end
Tool.Ammo.Value = Tool.Ammo.Value - 1
upGui()
wait(0.075)
for _,muzzleinstance in ipairs(Barrel:GetChildren()) do
if string.sub(muzzleinstance.Name, 1, 6) == 'Muzzle' then
muzzleinstance.Enabled = false
Anim:Stop()
end
end
Enabled = true
end
function reloadWep()
if Tool.Ammo.Value < Tool.Ammo.MaxValue then
Reloading = true
Firing = false
Tool.Handle.Reload:Play()
wait(ReloadTime)
Tool.Ammo.Value = Tool.Ammo.MaxValue
Reloading = false
upGui()
end
end
function upGui()
if AmmoGui then
AmmoGui.Counter.Max.Text = tostring(Tool.Ammo.MaxValue)
AmmoGui.Counter.Curr.Text = tostring(Tool.Ammo.Value)
end
end
Tool.Equipped:connect(function (mouse)
Character = Tool.Parent
Player = game:GetService('Players'):GetPlayerFromCharacter(Character)
mouse.Icon = 'rbxassetid://24007329'
AmmoGui = Tool.AmmoDisplay:Clone()
AmmoGui.Parent = Player.PlayerGui
upGui()
if Handle:FindFirstChild('Equip') then
Handle.Equip:Play()
end
mouse.Button1Down:connect(function ()
if Enabled and (not Reloading) then
Firing = true
end
while Firing == true do
if Enabled and (not Reloading) then
if Tool.Ammo.Value == Tool.Ammo.MinValue then
reloadWep()
else
fireGun(Barrel.CFrame.p, mouse.Hit.p, 999)
end
end
wait()
end
end)
mouse.Button1Up:connect(function ()
Firing = false
end)
mouse.KeyDown:connect(function (key)
if key == 'r' then
if Enabled and (not Reloading) and Tool.Ammo.Value < Tool.Ammo.MaxValue then
AnimR:Play()
reloadWep()
end
end
end)
end)
Tool.Unequipped:connect(function ()
if Character then
Character = nil
end
if Player then
Player = nil
end
for _,sound in ipairs(Handle:GetChildren()) do -- In attempt to stop the glitch
if sound:IsA('Sound') then
sound:Stop()
sound.TimePosition = 0
end
end
Firing = false
if AmmoGui then
AmmoGui:Destroy()
AmmoGui = nil
end
end)

5 comments
Scrap it all. You have to do this on the Server...
Wouldn't I just copy the script and make it sever sided and have a local activate it?
In future, remember to format your code. Secondly, scrap it all, remake the code. Remember to separate what belongs on the server into a server script and what belongs on the client into a local script; and use remote events for server-client/client-server communication.
Ok thank yoy
shouldn't you delete this post? I mean it's totally messed up. And the only mistake you did was i think damaging the player with a local script