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

Why does this error pop up?

Asked by 8 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.
02:52:24.293 - BodyHead is not a valid member of Model
02:52:24.294 - Script 'Players.Player.PlayerGui.Runner', Line 110 - global Bullet
02:52:24.294 - Script 'Players.Player.PlayerGui.Runner', Line 187
02:52:24.294 - Stack End

I get this error? Even though I removed this line from the script itself.

Edit: The Script

recoil = 0.0075
kick = 0.025
mindamage = 60
maxdamage = 80
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Character = Player.Character
Camera = game.Workspace.CurrentCamera
Neck = Character.Torso.Neck;
crouching = false
RoF = 0.075
Primary = script.Parent.Primary
Secondary = script.Parent.Secondary
MagDisplay = script.Parent.AmmoGui.Ammo.MagDisplay
FireModeDisplay = script.Parent.AmmoGui.Ammo.FireModeDisplay
Gui = Player.PlayerGui
MagAmmo = Gui.Values["M4"].MagAmmo
Ammo = Gui.Values["M4"].Ammo
Mags = Gui.Values["M4"].Mags
FireMode = Gui.Values["M4"].FireMode
FireMode2 = Gui.Values["M4"].FireMode2
Shooting = false
Sprinting = false
Reloading = false
Aiming=false
Character.Humanoid.WalkSpeed = 13
Mouse.Icon = "rbxasset://textures/Blank.png"

FireModeDisplay.Text = ""..FireMode.Value..""
MagDisplay.Text = ""..Mags.Value..""

RightArmWeld.C0 = CFrame.new(-2.3, -0.9, 0.2) *CFrame.Angles(math.rad(90), math.rad(0), math.rad(90))
LeftArmWeld.C0 = CFrame.new(0, -1.5, -0.75) *CFrame.Angles(math.rad(90), math.rad(25), math.rad(110))
GunWeld.C0 = CFrame.new(0, 0, -1.4) *CFrame.Angles(math.rad(-40), math.rad(90), math.rad(0))
RightArmWeldG.C0 = CFrame.new(-1, -1, 0.25) *CFrame.Angles(math.rad(90), math.rad(0), math.rad(90))
LeftArmWeldG.C0 = CFrame.new(0.5, -1, -0.5) *CFrame.Angles(math.rad(95), math.rad(15), math.rad(120))
GunWeldG.C0 = CFrame.new(0.5, -1, -1.4) *CFrame.Angles(math.rad(90), math.rad(15), math.rad(120))
_G.Animate.tweenWeld(GunWeld, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 15, true)
_G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 15, true)

function Bullet()
local Ray = Ray.new(Character.BodyHead.CFrame.p, (Mouse.Hit.p - Character.BodyHead.CFrame.p).unit * 999)
local Ignore = {Player.Character, Camera}
local PartHit, PositionHit = Workspace:FindPartOnRayWithIgnoreList(Ray, Ignore)
if PartHit and PartHit.Parent:FindFirstChild("Humanoid") then
     PartHit.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage))
end;
if PartHit and PartHit.Name=="Main" then
    PartHit.Parent.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage))
end;
if PartHit and PartHit.Name=="Part" then
    PartHit.Parent.Parent.Humanoid:TakeDamage(math.random(mindamage, maxdamage))
end;
MagAmmo.Value = MagAmmo.Value-1
GunG.Fire:Play()
end

function Fire(key)
if key == "v" then
if FireMode2.Value == false then
_G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(0, -1, -1) *CFrame.Angles(math.rad(90), math.rad(0), math.rad(145)), 20, true)
FireMode.Value = "Semi"
FireMode2.Value = true
wait(0.5)
FireModeDisplay.Text = ""..FireMode.Value..""
_G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(0.5, -1, -0.5) *CFrame.Angles(math.rad(95), math.rad(15), math.rad(120)), 20, true)
elseif FireMode2.Value == true then
_G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(0, -1, -1) *CFrame.Angles(math.rad(90), math.rad(0), math.rad(145)), 20, true)
FireMode.Value = "Auto"
FireMode2.Value = false
wait(0.5)
FireModeDisplay.Text = ""..FireMode.Value..""
_G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(0.5, -1, -0.5) *CFrame.Angles(math.rad(95), math.rad(15), math.rad(120)), 20, true)
end
end
end
Mouse.KeyDown:connect(Fire)

function Shoot()
if FireMode2.Value == false then
if Reloading == true or Sprinting == true or Shooting == true or MagAmmo.Value <=0 then return end;
    Shooting = true
    repeat
    wait(RoF)
    Bullet();
    until Shooting == false or MagAmmo.Value<=0
elseif FireMode2.Value == true then
if Reloading == true or Shooting == true or Sprinting == true or MagAmmo.Value<=0 then return end;
    Shooting = true
    wait(RoF)
    Bullet();
    Shooting = false
end
end
Mouse.Button1Down:connect(Shoot)

function StopShoot()
    Shooting=false
end
Mouse.Button1Up:connect(StopShoot)

function Sprinting(key)
if Reloading==true then return end
    if key=="0"then
        Sprinting = true
        _G.Animate.tweenWeld(GunWeld, 0, CFrame.new(0, -0.7, -1.4) *CFrame.Angles(math.rad(0), math.rad(130), math.rad(0)), 20, true)
        _G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(0, -0.7, -1.4) *CFrame.Angles(math.rad(0), math.rad(130), math.rad(0)), 20, true)
        Character.Humanoid.WalkSpeed = 18
    end
end
Mouse.KeyDown:connect(Sprinting)

function Stopped(key)
    if key=="0"then
        Sprinting = false
        _G.Animate.tweenWeld(GunWeld, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 15, true)
        _G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 15, true)
        Character.Humanoid.WalkSpeed = 13
    end
end
Mouse.KeyUp:connect(Stopped)

function Aimin()
if Sprinting == true or Reloading == true then return end;
    _G.Animate.tweenWeld(GunWeld, 0, CFrame.new(0, -0.26, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 20, true)
    _G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(0, -0.26, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 20, true)
    _G.Animate.tweenFoV(45, 100)
    Character.Humanoid.WalkSpeed = 9
    Aiming = true
end
Mouse.Button2Down:connect(Aimin)

function Aimout()
    _G.Animate.tweenWeld(GunWeld, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 20, true)
    _G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 20, true)
    _G.Animate.tweenFoV(70, 120)
    Character.Humanoid.WalkSpeed = 13
    Aiming = false
end
Mouse.Button2Up:connect(Aimout)

function Reload(key)
if Shooting == true or Aiming == true or Sprinting == true or Mags.Value <=0 or Reloading == true then return end;
    if key == "r" then
        Reloading = true
        MagAmmo.Value = MagAmmo.Value - MagAmmo.Value
        Mags.Value = Mags.Value -1
        _G.Animate.tweenWeld(GunWeld, 0, CFrame.new(1, 0, -1.4) *CFrame.Angles(math.rad(20), math.rad(100), math.rad(0)), 25, true)
        _G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(1, 0, -1.4) *CFrame.Angles(math.rad(15), math.rad(90), math.rad(0)), 15, true)
        wait(0.2)
        _G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(-0.7, -1.75, -1.75) *CFrame.Angles(math.rad(90), math.rad(25), math.rad(140)), 25, true)
        wait(0.4)
        GunG.MagOut:Play()
        _G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(-0.7, -1.75, -1.75) *CFrame.Angles(math.rad(90), math.rad(-25), math.rad(140)), 25, true)
        _G.Animate.tweenWeld(Gun.MagWeld, 0, CFrame.new(0, -2, 0) *CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)), 30, true)
        wait(0.3)
        Gun.Parent.Mag.Transparency = 1
        _G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(-0.7, -1.75, -1.75) *CFrame.Angles(math.rad(90), math.rad(-25), math.rad(180)), 25, true)
        wait(0.2)
        Gun.Rustle:Play()
        wait(0.8)
        Gun.Rustle:Stop()
        _G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(-0.7, -1.75, -1.75) *CFrame.Angles(math.rad(90), math.rad(-25), math.rad(140)), 25, true)
        wait(0.1)
        Gun.Parent.Mag.Transparency = 0
        wait(0.4)
        GunG.MagIn:Play()
        _G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(-0.7, -1.75, -1.75) *CFrame.Angles(math.rad(90), math.rad(25), math.rad(140)), 25, true)
        _G.Animate.tweenWeld(Gun.MagWeld, 0, CFrame.new(0, 0, 0) *CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)), 28, true)
        wait(0.45)
        _G.Animate.tweenWeld(GunWeld, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 20, true)
        _G.Animate.tweenWeld(GunWeldG, 0, CFrame.new(1, -0.5, -1.4) *CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)), 15, true)
        _G.Animate.tweenWeld(LeftArmWeld, 0, CFrame.new(0, -1.5, -0.75) *CFrame.Angles(math.rad(90), math.rad(25), math.rad(110)), 20, true)
        Reloading = false
        MagAmmo.Value = MagAmmo.Value + Ammo.Value
        MagDisplay.Text = ""..Mags.Value..""
    end
end
Mouse.KeyDown:connect(Reload)
end
2
Please post the script this error is referencing. Pyrondon 2089 — 8y
0
There's the script. ScriptingCon 52 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

On line 110 or 187, you're looking for an instance "BodyPart" inside some model, which doesn't exist/isn't created yet.

Ad

Answer this question