Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Gun script does no damage?

Asked by 9 years ago

Hi SH,

I'm trying to make a game but I cannot for the life of me figure out why this script does no damage. It's annoying.

--Decs

--[[_PRINT=function(m)
local i=Instance.new("StringValue")
i.Value=m
i.Parent=game.Workspace.PRINT
end]]

Player=game.Players.LocalPlayer
Tool=script.Parent
Handle=Tool.Barrel
Debris=game:GetService("Debris")

    --GunStats
    MagSize=30
    FireRate=1.6
    Accuracy=.15
    Damage=100
    ReloadTime=1.6
    MaxRange=999
    --States
    Ammo=MagSize
    Enabled=true
    Firing=false
    Equipped=false
    MouseDown=true
    Reloading=false 

    --Laser
    LaserPart=Instance.new("Part")
    LaserPart.Name="Bullet"
    LaserPart.formFactor=0
    LaserPart.BrickColor=BrickColor.new("Really red")
    LaserPart.Anchored=true
    LaserPart.CanCollide=false
    LaserPart.Locked=true
    LaserPart.Size=Vector3.new(1, 1, 1)
    LaserPart.TopSurface=0
    LaserPart.BottomSurface=0
    Mesh=Instance.new("SpecialMesh", LaserPart)
    Mesh.MeshType="Brick"
    Mesh.Name="Mesh"
    Mesh.Scale=Vector3.new(.2, .2, 1)

    --Tag
    creator=Instance.new("ObjectValue")
    creator.Name="creator"
    creator.Value=Player

--Funcs
ray_Cast=function(start,finish,ign) --Returns Part,Position
local AimVector=(finish-start).unit
local HitPart,HitPos=game.Workspace:FindPartOnRay(Ray.new(start,AimVector*MaxRange),ign)
    if HitPart and HitPos then
        if HitPart.Transparency==1 or HitPart.Name=="Bullet" then
        HitPart,HitPos=ray_Cast(HitPos,AimVector*MaxRange,ign)
        end
    end
return HitPart,HitPos
end

_Dammage=function(Hum)
local Emn=game.Players:GetPlayerFromCharacter(Hum.Parent)
    if Emn and (Emn~=Player) then
        if Emn.TeamColor~=Player.TeamColor then
        local tag=creator:clone()
        tag.Parent=Hum
        delay(.4,function()tag:Destroy()end)
        Hum:TakeDamage(Damage)
        end
    end
end

gun_Fire=function(aim)
Tool.Name="["..Ammo.."]"
local RayOrigin=Player.Character.Head.Position
local PartOrigin=Handle.Position
local FrDist=(PartOrigin-aim).magnitude
local spread=Accuracy
local FinalAim=Vector3.new((aim.x)+(math.random(-(spread/10)*FrDist,(spread/10)*FrDist)),(aim.y)+(math.random(-(spread/10)*FrDist,(spread/10)*FrDist)),(aim.z)+(math.random(-(spread/10)*FrDist,(spread/10)*FrDist)))
local HitPart,HitPos=ray_Cast(RayOrigin,FinalAim,Player.Character)
local BulletLength=(PartOrigin-HitPos).magnitude
local CFram=CFrame.new(PartOrigin,HitPos)
local Laser1,Laser2=LaserPart:clone(),LaserPart:clone()
Laser1.CFrame=CFram*CFrame.new(0,0,-BulletLength*.75)
Laser1.Mesh.Scale=Vector3.new(Laser1.Mesh.Scale.x,Laser1.Mesh.Scale.y,BulletLength*.5)
Laser2.CFrame=CFram*CFrame.new(0,0,-BulletLength*.25)
Laser2.Mesh.Scale=Vector3.new(Laser1.Mesh.Scale.x,Laser1.Mesh.Scale.y,BulletLength*.5)  
Laser1.Parent=game.Workspace Laser2.Parent=game.Workspace
Debris:AddItem(Laser2,.03)
Debris:AddItem(Laser1,.06)
    if HitPart then
    local Hum=HitPart.Parent:FindFirstChild("Humanoid")
        if not Hum then
        Hum=HitPart.Parent.Parent:FindFirstChild("Humanoid")
        end
        if Hum then
        _Dammage(Hum)
        end
    end
end

_Reload=function(mouse)
    if not Reloading then
    Handle.Reload:Play()
    Tool.Name="[REL]"
    mouse.Icon="rbxasset://textures\\GunWaitCursor.png"
    Reloading=true
    wait(ReloadTime)
    Enabled=true
    Ammo=MagSize
    Reloading=false
    mouse.Icon="rbxasset://textures\\GunCursor.png"
    Tool.Name="["..Ammo.."]"
    end
end

mouseDown=function(mouse)
MouseDown=true
    if Firing==false then
        while (MouseDown and not Reloading) and (Ammo>0) do
        Firing=true
        Ammo=Ammo-1
        Handle.Fire:Play()
        gun_Fire(mouse.hit.p)
        wait(FireRate)
        end 
    Firing=false
    end
    if Ammo<=0 then
    _Reload(mouse)
    end
end

mouseUp=function(mouse)
MouseDown=false
end

keyDown=function(mouse,key)
    if key=="r" then
    _Reload(mouse)
    end
end

Tool.Equipped:connect(function(mouse)
    Player.Character.Humanoid.Changed:connect(function(p) 
        if p=="Health" and Player.Character.Humanoid.Health<=0 then
        Tool:remove()
        end
    end)
Tool.Name="["..Ammo.."]"
mouse.Icon="rbxasset://textures\\GunCursor.png"
Equipped=true
mouse.Button1Down:connect(function() mouseDown(mouse) end)
mouse.Button1Up:connect(function() mouseUp(mouse) end)
mouse.KeyDown:connect(function(key) keyDown(mouse,key) end)
end)

Tool.Unequipped:connect(function()
Equipped=false
MouseDown=false
end)






 mouse=game.Players.LocalPlayer

mouse.MouseButton1Down:connect(function()
if mouse.Target then
if mouse.Target.Parent:FindFirstChild("Humanoid")~=nil then
mouse.Target.Parent.Humanoid:TakeDamage(100)
elseif mouse.Target.Parent.Parent:FindFirstChild("Humanoid")~=nil then
mouse.Target.Parent.Parent.Humanoid:TakeDamage(100)
end
end
end)

What am I doing wrong?

2
What are you doing wrong? Making us fix a 179 line script. EzraNehemiah_TF2 3552 — 9y
1
@LordDragonZord XD so true! yumtaste 476 — 9y
0
I thought providing the complete script was a good idea. Sorry! broetchen 0 — 9y

Answer this question