I made this script, but the gun is poorly optimized. I want to optimize it, but I don't know much about that.
Server:
local Arma = script.Parent
local Servicios = {PLS = game:GetService("Players")}
Arma.CF:WaitForChild("Disparo").OnServerEvent:Connect(function(Jugador, Raton)
local Psj = Jugador.Character
local Rayo, Deteccion = Ray.new(Arma.Handle.CFrame.p, (Raton - Arma.Handle.CFrame.p).unit * 300)
local Detector = workspace:FindPartOnRay(Rayo, Psj, false, true)
local Bala = Arma.CF:WaitForChild("Bala"):Clone() Bala.Parent = workspace
Bala.Anchored = false
Bala.CFrame = CFrame.new(Arma.Salida_de_bala.CFrame.p)
Bala.CFrame = CFrame.new(Bala.Position, Raton)
local Fuerza = Instance.new("BodyForce", Bala)
Fuerza.Force = Vector3.new(0, workspace.Gravity, 0)*Bala:GetMass()
local Velo = Instance.new("BodyThrust", Bala)
Velo.Force = Vector3.new(0, 0, -500)
local Attach0 = Instance.new("Attachment", Bala)
Attach0.Position = Vector3.new(0, 0.10, 0)
local Attach1 = Instance.new("Attachment", Bala)
Attach1.Position = Vector3.new(0, -0.10, 0)
Bala.R.Attachment0 = Attach0
Bala.R.Attachment1 = Attach1
Arma.Salida_de_bala.Efecto:Play()
game:GetService("Debris"):AddItem(Bala, 1.5)
Arma.Salida_de_bala.Particula.Transparency = NumberSequence.new(.7)
wait(.01)
Arma.Salida_de_bala.Particula.Transparency = NumberSequence.new(1)
if Detector then
if Servicios.PLS:GetPlayerFromCharacter(Detector.Parent) then
Detector.Parent.Humanoid:TakeDamage(20)
wait(.001)
Bala:Destroy()
else
wait(1)
Bala:Destroy()
end
end
end)
Client:
local Servicios = {UIS = game:GetService("UserInputService"), PLS = game:GetService("Players")}
local Jugador = Servicios.PLS.LocalPlayer
local Psj = Jugador.CharacterAdded:Wait()
local Camara = workspace.CurrentCamera
local Arma = script.Parent
local Salida_M = Arma:WaitForChild("Salida_M")
local Autorizacion = true
Arma.Equipped:Connect(function(Raton)
local Pose = Psj:WaitForChild("Humanoid"):LoadAnimation(Arma.CF.Pose)
Pose:Play()
local Clon = script.Parent.CF.Panta Clon.Parent = Jugador.PlayerGui
local Carga = Clon.Balas:WaitForChild("Carga")
local Valor = Carga:WaitForChild("Valor")
local RatonX = Raton.Button1Down:Connect(function()
if Valor.Value <= 20 and Autorizacion == true then
Valor.Value = Valor.Value - 1
Arma.CF:WaitForChild("Disparo"):FireServer(Raton.Hit.p)
wait(.1)
Carga.Text = Valor.Value.."/20"
end
if Valor.Value <= 0 then
Autorizacion = false
end
end)
local US = Servicios.UIS.InputBegan:Connect(function(Tecla, Activo)
if not Activo then
if Valor.Value <= 19 then
if Tecla.UserInputType == Enum.UserInputType.Keyboard then
if Tecla.KeyCode == Enum.KeyCode.R then
Autorizacion = false
Salida_M.Recarga:Play()
local Recargar = Jugador.Character.Humanoid:LoadAnimation(Arma.CF.Recargar)
Valor.Value = tonumber(20)
Recargar:Play()
wait(.1)
local Municion = Arma.CF.Municion:Clone() Municion.Parent = workspace
Municion.CFrame = CFrame.new(Salida_M.CFrame.p)
Municion.Anchored = false
Municion.Transparency = 0
Recargar:Stop()
wait(.7)
Carga.Text = Valor.Value.."/20"
Municion:Remove()
Autorizacion = true
end
end
end
end
end)
Arma.Unequipped:Connect(function()
Pose:Stop()
Salida_M.Recarga:Stop()
Clon.Parent = Arma.CF
US:Disconnect()
RatonX:Disconnect()
end)
end)

2 comments
Is this your script? First, you should look for any deprecated code. One of them being the second parameter to Instance.new(). The parent parameter is deprecated so use Object.Parent instead.
Yes, is my script, I speak spanish. Okay, i going to try it.