Lua 如果我趁枪还没打爆它';s拍摄(突发和自动)停止工作-ROBLOX工作室

Lua 如果我趁枪还没打爆它';s拍摄(突发和自动)停止工作-ROBLOX工作室,lua,roblox,Lua,Roblox,请想办法解决它:/I我不太擅长编写脚本。 还有另一个脚本:服务器脚本。但我不认为这是这个问题的原因。 不管怎样我都会把它寄出去 顺便说一句,这是我正在制作的射击游戏(只是为了添加一些工作,我可以发布它) 当它中断时,会发出以下信息: 19:31:45.103 Humanoid不是背包“Players.xxfilippoxx33.Backpack”的有效成员-客户端-Gun_脚本:178 19:31:45.103堆栈开始-Studio 19:31:45.103脚本“Players.xxfilipp

请想办法解决它:/I我不太擅长编写脚本。
还有另一个脚本:服务器脚本。但我不认为这是这个问题的原因。
不管怎样我都会把它寄出去

顺便说一句,这是我正在制作的射击游戏(只是为了添加一些工作,我可以发布它)

当它中断时,会发出以下信息:

19:31:45.103 Humanoid不是背包“Players.xxfilippoxx33.Backpack”的有效成员-客户端-Gun_脚本:178
19:31:45.103堆栈开始-Studio
19:31:45.103脚本“Players.xxfilippoxx33.Backpack.Assualt Rifle.Gun_脚本”,第178行-功能射击-工作室-Gun_脚本:178
19:31:45.104脚本“Players.xxfilippoxx33.Backpack.Assualt Rifle.Gun_脚本”,第314行-功能按钮1向下-工作室-Gun_脚本:314
19:31:45.104脚本“Players.xxfilippoxx33.Backpack.Assualt Rifle.Gun_脚本”,第367行-工作室-Gun_脚本:367
19:31:45.104堆栈结束-工作室
这是本地脚本

--// Created by Nightrains            

local localPlayer = game.Players.LocalPlayer
local sp = script.Parent

--// Wait For Children

sp:WaitForChild("Handle")
sp:WaitForChild("Ammo")

sp.Handle:WaitForChild("Equip")
sp.Handle:WaitForChild("Fire")
sp.Handle:WaitForChild("Reload")
sp.Handle:WaitForChild("Trigger")
sp.Handle:WaitForChild("PointLight")

--// Gun Configuration

local CanTeamkill = false
local FirstPersonArms = true
local HeadshotDamage = true
local IgnoreHats = true

local ClipSize=30
local ReloadTime=2.3
local Firerate=.3
local MinSpread=0.15
local MaxSpread=0.15
local SpreadRate=0.3
local BaseDamage= 20
local Spread=0.15
local automatic=false
local burst=true
local shot=false            --Shotgun
local BarrlePos=Vector3.new(-2.5,.60,0)
local Cursors={"rbxasset://textures\\GunCursor.png"}
local ReloadCursor="rbxasset://textures\\GunWaitCursor.png"
-------------------------------------
local equiped=false


local enabled=true
local reloading=false
local down=false
local r=game:service("RunService")

local Bullet=Instance.new("Part")
Bullet.Name="Bullet"
Bullet.BrickColor=BrickColor.new("Bright yellow")
Bullet.Anchored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.new(1,1,1)
Bullet.formFactor=0
Bullet.TopSurface=0
Bullet.BottomSurface=0
Bullet.Material = Enum.Material.Neon
local Mesh=Instance.new("SpecialMesh")
Mesh.Parent=Bullet
Mesh.MeshType="Brick"
Mesh.Name="Mesh"
Mesh.Scale=Vector3.new(.15,.15,1)

local pointLight = sp.Handle.PointLight

local Debris = game:GetService("Debris")

local gunServer = game:GetService("ReplicatedStorage"):WaitForChild("GunRemotes")

local remote = {
    TagHumanoid = gunServer:WaitForChild("TagHumanoid"),
    FireServer = gunServer:WaitForChild("FireServer"),
    TakeDamage = gunServer:WaitForChild("TakeDamage"),
    PlaySound = gunServer:WaitForChild("PlaySound"),
}
local ContextActionService = game:GetService("ContextActionService")

-------------------------------------------------------------------------------

game.Workspace.ChildAdded:Connect(function(child)
    if child.Name == localPlayer.Name.."Bullet" then
        child.Transparency = 1
    end
end)

local function reload(mouse)
    remote.PlaySound:FireServer(sp.Handle.Reload)
    reloading=true
    mouse.Icon=ReloadCursor
    while sp.Ammo.Value<ClipSize and reloading and enabled do
        wait(ReloadTime/ClipSize)
        if reloading then
            sp.Ammo.Value=sp.Ammo.Value+1
        else
            break
        end
    end
    mouse.Icon=Cursors[1]
    reloading=false
end

local function reload_Mob()
    remote.PlaySound:FireServer(sp.Handle.Reload)
    reloading=true
    while sp.Ammo.Value<ClipSize and reloading and enabled do
        wait(ReloadTime/ClipSize)
        if reloading then
            sp.Ammo.Value=sp.Ammo.Value+1
        else
            break
        end
    end
    reloading=false
end
script.Parent.Equipped:Connect(function()
    ContextActionService:SetPosition("ReloadButton",UDim2.new(0.72,-25,0.20,-25))
end)

script.Parent.Unequipped:Connect(function()
    ContextActionService:SetPosition("ReloadButton",UDim2.new(2.72,-9,0.20,-80))
end)

local function onKeyDown(key,mouse)
    key=key:lower()
    if key=="r" and not reloading then
        reload(mouse)
    end
end

function onButtonPress()
    wait(0.1)   
    if onButtonPress() and not reloading then
    if script.Parent.Ammo.Value < 30 then
        wait(0.1)
        reload_Mob()
    end
        script.Parent:reload(button)
    end
end 

local mobilebutton = ContextActionService:BindAction("ReloadButton",onButtonPress,true,"R")
ContextActionService:SetPosition("ReloadButton",UDim2.new(2.72,-90,.20,-25))

local function getIgnoreList()
    local list = {localPlayer.Character}
    for _,child in pairs(game.Workspace:GetDescendants()) do
        if child:IsA("BasePart") then
            if not child.CanCollide then
                if child.Name == "Handle" and IgnoreHats then
                    table.insert(list,child)
                elseif child.Name ~= "Handle" and not child.Parent:FindFirstChild("Humanoid") then
                    table.insert(list,child)
                end
            end
        end
    end
    return list
end

local function bulletEffect(bullet,distance)
    if distance > 40 then
        local bulletLength = distance/2
        bullet.Mesh.Scale=Vector3.new(.15,.15,bulletLength)
        bullet.Mesh.Offset=Vector3.new(0,0,bulletLength/2)
        while bullet.Mesh.Offset.Z > (bulletLength/2)*-1 do
            wait()
            bullet.Mesh.Offset=Vector3.new(0,0,bullet.Mesh.Offset.Z-20) 
        end
    else
        bullet.Mesh.Scale=Vector3.new(.15,.15,distance)
        bullet.Mesh.Offset=Vector3.new(0,0,distance/2)
        wait(0.03)
    end
    bullet:Destroy()
end

local function fire(aim)
    if sp.Parent.Humanoid.Health < 1 then
        return
    end
    remote.PlaySound:FireServer(sp.Handle.Fire)
    
    t=r.Stepped:wait()
    last6=last5
    last5=last4
    last4=last3
    last3=last2
    last2=last
    last=t
    local bullet=Bullet:clone()
    local startpoint=sp.Handle.CFrame*BarrlePos
    local ray = Ray.new(startpoint, (aim - startpoint).unit * 300)
    local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, getIgnoreList(), false, true)
    local distance = (startpoint - position).magnitude
    bullet.Parent=game.Workspace.CurrentCamera
    
    remote.FireServer:FireServer(startpoint,position,pointLight)
    
    if hit~=nil then
        local humanoid=hit.Parent:FindFirstChild("Humanoid")
        if not humanoid then
            humanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
        end
        if humanoid~=nil then
            local damage=math.random(BaseDamage-(BaseDamage*.25),BaseDamage+(BaseDamage*.25))
            local headshot = false
            if hit.Name=="Head" and HeadshotDamage then
                damage=damage*1.3
                --headshot = true
            else
                damage=damage*.75
            end
            if humanoid.Health>0 then
                local eplr=game.Players:playerFromCharacter(humanoid.Parent)
                local plr=game.Players:playerFromCharacter(sp.Parent)
                if eplr~=nil and plr~=nil then
                    if CanTeamkill then
                        remote.TagHumanoid:FireServer(humanoid)
                        remote.TakeDamage:FireServer(humanoid,damage,headshot)
                    else
                        if eplr.TeamColor~=plr.TeamColor or eplr.Neutral or plr.Neutral then
                            remote.TagHumanoid:FireServer(humanoid)
                            remote.TakeDamage:FireServer(humanoid,damage,headshot)
                        end 
                    end
                else
                    remote.TagHumanoid:FireServer(humanoid)
                    remote.TakeDamage:FireServer(humanoid,damage,headshot)
                end
            end
        end
    end
    if distance > 40 then
        bullet.CFrame=CFrame.new(startpoint, position) * CFrame.new(0, 0, -distance / 2)
    else
        bullet.CFrame=CFrame.new(startpoint, position) * CFrame.new(0, 0, -distance)
    end
    spawn(function()
        bulletEffect(bullet,distance)
    end)
end


local ObjectLocalTransparencyModifier
local RunService = game:GetService("RunService")
local LocalObjects = {}
local function setArmsTransparency(Limb)
    if FirstPersonArms then
        local value = {Object = Limb, Transparency = 0, AutoUpdate = true}  
        pcall(function()
            local ObjectFound = false
            for i, v in pairs(LocalObjects) do
                if v == value then
                    ObjectFound = true
                end
            end
            if not ObjectFound then
                table.insert(LocalObjects, value)
                if ObjectLocalTransparencyModifier then
                    ObjectLocalTransparencyModifier:disconnect()
                end
                ObjectLocalTransparencyModifier = RunService.RenderStepped:connect(function()
                    local Camera = game:GetService("Workspace").CurrentCamera
                    for i, v in pairs(LocalObjects) do
                        if v.Object and v.Object.Parent then
                            local CurrentTransparency = v.Object.LocalTransparencyModifier
                            local ViewDistance = (Camera.CoordinateFrame.p - sp.Parent.Head.Position).Magnitude
                            if ((not v.AutoUpdate and (CurrentTransparency == 1 or CurrentTransparency == 0)) or v.AutoUpdate) then
                                if ((v.Distance and ViewDistance <= v.Distance) or not v.Distance) then
                                    v.Object.LocalTransparencyModifier = v.Transparency
                                else
                                    v.Object.LocalTransparencyModifier = 0
                                end
                            end
                        else
                            table.remove(LocalObjects, i)
                        end
                    end
                end)
            end
        end)
    end
end

local function onButton1Up(mouse)
    down=false
end

local  function onButton1Down(mouse)
    local h=sp.Parent:FindFirstChild("Humanoid")
    if not enabled or reloading or down or h==nil then
        return
    end
    if sp.Ammo.Value>0 and h.Health>0 then
        down=true
        enabled=false
        while down do
            if sp.Ammo.Value<=0 then
                break
            end
            if burst then
                local startpoint=sp.Handle.CFrame*BarrlePos
                local mag=(mouse.Hit.p-startpoint).magnitude
                local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
                fire(mouse.Hit.p+rndm)
                sp.Ammo.Value=sp.Ammo.Value-1
                if sp.Ammo.Value<=0 then
                    break
                end
                wait(.05)
                local startpoint=sp.Handle.CFrame*BarrlePos
                local mag2=((mouse.Hit.p+rndm)-startpoint).magnitude
                local rndm2=Vector3.new(math.random(-(.1/10)*mag2,(.1/10)*mag2),math.random(-(.1/10)*mag2,(.1/10)*mag2),math.random(-(.1/10)*mag2,(.1/10)*mag2))
                fire(mouse.Hit.p+rndm+rndm2)
                sp.Ammo.Value=sp.Ammo.Value-1
                if sp.Ammo.Value<=0 then
                    break
                end
                wait(.05)
                fire(mouse.Hit.p+rndm+rndm2+rndm2)
                sp.Ammo.Value=sp.Ammo.Value-1
            elseif shot then
                sp.Ammo.Value=sp.Ammo.Value-1
                local startpoint=sp.Handle.CFrame*BarrlePos
                local mag=(mouse.Hit.p-startpoint).magnitude
                local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
                fire(mouse.Hit.p+rndm)
                local mag2=((mouse.Hit.p+rndm)-startpoint).magnitude
                local rndm2=Vector3.new(math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2))
                fire(mouse.Hit.p+rndm+rndm2)
                local rndm3=Vector3.new(math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2))
                fire(mouse.Hit.p+rndm+rndm3)
                local rndm4=Vector3.new(math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2))
                fire(mouse.Hit.p+rndm+rndm4)
            else
                sp.Ammo.Value=sp.Ammo.Value-1
                local startpoint=sp.Handle.CFrame*BarrlePos
                local mag=(mouse.Hit.p-startpoint).magnitude
                local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
                fire(mouse.Hit.p+rndm)
            end
            wait(Firerate)
            if not automatic then
                break
            end
        end 
        enabled=true
    else
        remote.PlaySound:FireServer(sp.Handle.Trigger)
    end
end

local function onEquippedLocal(mouse)
    remote.PlaySound:FireServer(sp.Handle.Equip)
    if mouse==nil then
        print("Mouse not found")
        return 
    end
    local Limbs = {"Right Arm", "RightHand", "RightUpperArm", "RightLowerArm",
        "Left Arm", "LeftHand", "LeftUpperArm", "LeftLowerArm"}
    for i, v in pairs(Limbs) do
        local Limb = sp.Parent:FindFirstChild(v)
        setArmsTransparency(Limb)
    end
    mouse.Icon=Cursors[1]
    mouse.KeyDown:connect(function(key) onKeyDown(key,mouse) end)
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
    mouse.Button1Up:connect(function() onButton1Up(mouse) end)
    
    equiped=true
    if #Cursors>1 then
        while equiped do
            t=r.Stepped:wait()
            local action=sp.Parent:FindFirstChild("Pose")
            if action~=nil then
                if sp.Parent.Pose.Value=="Standing" then
                    Spread=MinSpread
                else
                    Spread=MinSpread+((4/10)*(MaxSpread-MinSpread))
                end
            else
                Spread=MinSpread
            end
            if t-last<SpreadRate then
                Spread=Spread+.1*(MaxSpread-MinSpread)
            end
            if t-last2<SpreadRate then
                Spread=Spread+.1*(MaxSpread-MinSpread)
            end
            if t-last3<SpreadRate then
                Spread=Spread+.1*(MaxSpread-MinSpread)
            end
            if t-last4<SpreadRate then
                Spread=Spread+.1*(MaxSpread-MinSpread)
            end
            if t-last5<SpreadRate then
                Spread=Spread+.1*(MaxSpread-MinSpread)
            end
            if t-last6<SpreadRate then
                Spread=Spread+.1*(MaxSpread-MinSpread)
            end
            if not reloading then
                local percent=(Spread-MinSpread)/(MaxSpread-MinSpread)
                for i=0,#Cursors-1 do
                    if percent>(i/(#Cursors-1))-((1/(#Cursors-1))/2) and percent<(i/(#Cursors-1))+((1/(#Cursors-1))/2) then
                        mouse.Icon=Cursors[i+1]
                    end
                end
            end
            wait(Firerate*.9)
        end
    end
end
local function onUnequippedLocal(mouse)
    
    if ObjectLocalTransparencyModifier then
        ObjectLocalTransparencyModifier:disconnect()
    end
    local camera = game.Workspace.CurrentCamera
    if (camera.focus.p - camera.CoordinateFrame.p).magnitude <= 1 then
        for i, v in pairs(LocalObjects) do
            if v.Object then
                v.Object.LocalTransparencyModifier = 1
            end
        end
    end
    LocalObjects = {}
    
    equiped=false
    reloading=false
end
sp.Equipped:connect(onEquippedLocal)
sp.Unequipped:connect(onUnequippedLocal)
-->//由Nightrains创建
本地本地玩家=game.Players.localPlayer
本地sp=script.Parent
--//等孩子
sp:WaitForChild(“句柄”)
sp:WaitForChild(“弹药”)
sp.手柄:WaitForChild(“装备”)
sp.手柄:WaitForChild(“火灾”)
sp.句柄:WaitForChild(“重新加载”)
sp.句柄:WaitForChild(“触发器”)
sp.手柄:WaitForChild(“点光源”)
--//火炮配置
本地CanTeamkill=false
本地FirstPersonArms=true
本地头像损坏=真
本地IgnoreHats=true
本地ClipSize=30
本地重新加载时间=2.3
局部燃速=.3
本地分钟数=0.15
本地最大扩展=0.15
本地摊铺率=0.3
局部基底损伤=20
本地价差=0.15
本地自动=错误
本地突发=真
本地射击=假--猎枪
本地BarrlePos=Vector3.新(-2.5,60,0)
本地游标={”rbxasset://textures\\GunCursor.png“}
本地重新加载游标=”rbxasset://textures\\GunWaitCursor.png“
-------------------------------------
本地装备=错误
本地启用=真
本地重新加载=错误
本地向下=错误
本地r=游戏:服务(“运行服务”)
本地项目符号=Instance.new(“部分”)
Bullet.Name=“Bullet”
Bullet.BrickColor=BrickColor.new(“亮黄色”)
Bullet.archored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.新(1,1,1)
Bullet.formFactor=0
Bullet.上表面=0
子弹。底面=0
Bullet.Material=Enum.Material.Neon
局部网格=Instance.new(“SpecialMesh”)
Mesh.Parent=Bullet
Mesh.MeshType=“Brick”
Mesh.Name=“Mesh”
Mesh.Scale=Vector3.new(.15,15,1)
本地点光源=sp.Handle.pointLight
本地碎片=游戏:获取服务(“碎片”)
本地gunServer=game:GetService(“复制存储”):WaitForChild(“GunRemotes”)
本地远程={
TagHumanoid=gunServer:WaitForChild(“TagHumanoid”),
FireServer=gunServer:WaitForChild(“FireServer”),
TakeDamage=gunServer:WaitForChild(“TakeDamage”),
PlaySound=gunServer:WaitForChild(“PlaySound”),
}
本地ContextActionService=游戏:GetService(“ContextActionService”)
-------------------------------------------------------------------------------
游戏。工作区。儿童添加:连接(功能(儿童)
如果child.Name==localPlayer.Name.“Bullet”,则
child.Transparency=1
结束
(完)
本地函数重新加载(鼠标)
远程.PlaySound:FireServer(sp.Handle.Reload)
重新加载=真
mouse.Icon=ReloadCursor
而sp.Ammo.Value(bulletLength/2)*-1 do
等等
bullet.Mesh.Offset=Vector3.new(0,0,bullet.Mesh.Offset.Z-20)
结束
其他的
bullet.Mesh.Scale=Vector3.new(.15.15,距离)
bullet.Mesh.Offset=Vector3.new(0,0,距离/2)
等待(0.03)
结束
子弹:摧毁
结束
局部功能火灾(aim)
如果sp.Parent.Humanoid.Health<1,则
返回
结束
远程.PlaySound:FireServer(sp.Handle.Fire)
t=r.Stepped:wait()
last6=last5
last5=last4
last4=last3
last3=last2
last2=last
最后=t
本地项目符号=项目符号:克隆()
本地startpoint=sp.Handle.CFrame*BarrlePos
本地光线=光线。新(起始点,(目标-起始点)。单位*300)
本地命中,位置=工作区:FindPartOnRayWithIgnoreList(光线,getIgnoreList(),false,true)
局部距离=(起点-位置)。震级
bullet.Parent=game.Workspace.CurrentCamera
远程.FireServer:FireServer(起始点、位置、点光源)
如果命中~=nil,则
本地类人=命中。父对象:FindFirstChild(“类人”)
如果不是人形的话
humanoid=hit.Parent.Parent:FindFirstChild(“humanoid”)
结束
如果类人~=nil,那么
局部损伤=数学随机(基损伤-(基损伤*.25),基损伤+(基损伤*.25))
本地头像=假
如果命中。名称==“头部”和头部伤害,则
损坏=损坏*1.3
--头像=真
其他的
损坏=损坏*.75
结束
如果类人生命值>0,则
本地eplr=游戏。玩家:玩家角色(类人。父)
本地plr=游戏。玩家:玩家角色(sp.Parent)
如果eplr~=nil和plr~=nil,则
如果坎特基尔那么
TagHumanoid:FireServer(humanoid)
远程。攻击伤害:FireServer(类人,伤害,头像)
其他的
如果eplr.TeamColor~=plr.TeamColor或eplr.Neutral或plr.Neutral,则
TagHumanoid:FireServer(humanoid)
远程。攻击伤害:FireServer(类人,伤害,头像)
结束
结束
其他的
TagHumanoid:FireServer(humanoid)
远程。攻击伤害:FireServer(类人,伤害,头像)
结束
结束
结束
结束
如果距离>40,则
bullet.CFrame=CFrame.new(起始点,位置)*CFrame.new(0,
--PUT ME IN ServerScriptService.

local replicatedStorage = game.ReplicatedStorage
local debris = game:GetService("Debris")

local folder = Instance.new("Folder",replicatedStorage)
folder.Name = "GunRemotes"

local Bullet=Instance.new("Part")
Bullet.Name="Bullet"
Bullet.BrickColor=BrickColor.new("Bright yellow")
Bullet.Anchored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.new(1,1,1)
Bullet.formFactor=0
Bullet.TopSurface=0
Bullet.BottomSurface=0
Bullet.Transparency = 1
Bullet.Material = Enum.Material.Neon
local Mesh=Instance.new("SpecialMesh")
Mesh.Parent=Bullet
Mesh.MeshType="Brick"
Mesh.Name="Mesh"
Mesh.Scale=Vector3.new(.15,.15,1)

local function remote(name)
    local create = Instance.new("RemoteEvent",folder)
    create.Name = name
    return create
end

local fireServer = remote("FireServer")
fireServer.OnServerEvent:connect(function(player,startpoint,pos)
    local newBullet = Bullet:Clone()
    newBullet.Name = player.Name.."Bullet"
    local distance=(startpoint-pos).magnitude
    local bulletLength = distance/2
    if distance > 40 then
        newBullet.CFrame=CFrame.new(startpoint, pos) * CFrame.new(0, 0, -distance / 2)
        newBullet.Mesh.Scale=Vector3.new(.15,.15,bulletLength)
        newBullet.Mesh.Offset=Vector3.new(0,0,bulletLength/2)
    else
        newBullet.CFrame=CFrame.new(startpoint, pos) * CFrame.new(0, 0, -distance)
        newBullet.Mesh.Scale=Vector3.new(.15,.15,distance)
        newBullet.Mesh.Offset=Vector3.new(0,0,distance/2)
    end
    newBullet.Transparency = 0
    newBullet.Parent = game.Workspace
    if distance > 40 then
        while newBullet.Mesh.Offset.Z > (bulletLength/2)*-1 do
            wait()
            newBullet.Mesh.Offset=Vector3.new(0,0,newBullet.Mesh.Offset.Z-20) 
        end
    else
        wait(0.03)
    end
    newBullet:Destroy()
end)
fireServer.OnServerEvent:connect(function(_,_,_,light)
    light.Enabled = true
    wait(.05)
    light.Enabled = false
end)

remote("TagHumanoid").OnServerEvent:connect(function(player,humanoid)
    local tag = Instance.new("ObjectValue")
    tag.Value = player
    tag.Name = "creator"
    tag.Parent = humanoid
    delay(2,function()
        if tag ~= nil then
            tag.Parent = nil
        end
    end)
end)

remote("TakeDamage").OnServerEvent:connect(function(player,humanoid,damage,head)
    humanoid:TakeDamage(damage)
    if humanoid.Health < 1 and head then
        humanoid.Parent.Head:Destroy()
    end
end)

remote("PlaySound").OnServerEvent:connect(function(player,sound)
    sound:Play()
end)

remote("HumanoidSpeed").OnServerEvent:connect(function(player,humanoid,speed)
    humanoid.WalkSpeed = speed
end)
local function fire(aim)
    if sp.Parent.Humanoid.Health < 1 then
        return
    end
....
local humanoid=hit.Parent:FindFirstChild("Humanoid")
 if not humanoid then
   humanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
 end