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)
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