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

Head throw script kills me when I run it?

Asked by 6 years ago
Edited 6 years ago

I am making a script that makes you throw our head like an attack but when i run it kills me. The script is in a LocalScript in StarterPack

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()


Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "l" then
        local x = Player.Character.Head
        x.Neck:Destroy()
        x.CanCollide = false
        x.CFrame = Player.Character.UpperTorso.CFrame*CFrame.new(0,2,0)
        local v = Instance.new("BodyVelocity", x)
        v.Velocity = Player.Character.UpperTorso.CFrame.lookVector*90

        v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)



        x.Parent = workspace
        wait(1)

        x.BodyVelocity:Remove()

    else

    end
end)

0
you could instead just clone your head and make it invisible then use the clones head as the object your throwing :p Nikkulaos 229 — 6y
0
Removing the head kills the player, so do what Nikkulai suggested. Viking359 161 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

that script kills you because you're decapitating yourself.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()


game:GetService("UserInputService").InputBegan:connect(function(e) --changed to userinputservice instead of keydown as its deprecated
    if e.KeyCode == Enum.KeyCode.L then
    local h = Player.Character:FindFirstChild("Head")
        local x = h:Clone()
        x.Neck:Destroy()
        x.CanCollide = false
    x.CFrame = h.CFrame
    x.Parent = workspace
    h.Transparency = 1 --make head invisible
    local decal = h:FindFirstChild("face").Texture --store face decal
    h:FindFirstChild("face").Texture = nil --remove face decal
        local v = Instance.new("BodyVelocity", x)
        v.Velocity = Player.Character.UpperTorso.CFrame.lookVector*90

        v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

        wait(1)
    h:FindFirstChild("face").Texture = decal --remake face decal visible
    h.Transparency = 0 --remake head visible
        --x.BodyVelocity:Destroy() -- fixed :remove() because its deprecated
    x:Destroy() --removes head projectile- remove this line and uncomment the one above to only make the head fall
     else
    --unless you want to add something else if the key is not L, remove this else part.
    --btw if you want to add multiple abilities in one function, use elseif
    end
end)

tell me if something doesnt work right, i'll try to fix it

0
Lol, i told him this in the comments. Idk if he read it though. He might find this more useful though as its put into a script, and isnt just an explanation Nikkulaos 229 — 6y
Ad

Answer this question