Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Head throw script kills me when I run it?

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)

2 comments

0

you could instead just clone your head and make it invisible then use the clones head as the object your throwing :p

0

Removing the head kills the player, so do what Nikkulai suggested.

1 answer

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

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.