So I made a tool that when activated launches the player back but if the player dies then tries to use the tool. The tool stops working at the part that’s supposed to throw him back. I don’t know what’s wrong. This is the script:
local Tool = script.Parent;
local StarterGui = game:GetService("StarterGui")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
enabled = true
local function getModelMass(model: Model): number
local mass = 0
for _, v in ipairs(model:GetDescendants()) do
if v:IsA('BasePart') then
mass += v:GetMass()
end
end
return mass
end
local backwardsForce = getModelMass(character) * 400
script.Parent.Activated:Connect(function()
enabled = false
Tool.GripForward = Vector3.new(-.981, .196, 0)
Tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
Tool.GripRight = Vector3.new(0, -0, -1)
Tool.GripUp = Vector3.new(0.196, .981, 0)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
Tool.Handle.DrinkSound:Play()
wait(2.5)
local h = Tool.Parent:FindFirstChild("Humanoid")
if (h ~= nil) then
if (h.MaxHealth > h.Health + 1.6) then
h.Health = h.Health + 1.6
else
h.Health = h.MaxHealth
end
end
Tool.GripForward = Vector3.new(-1, 0, 0)
Tool.GripPos = Vector3.new(-.5, -.1, 0)
Tool.GripRight = Vector3.new(0, 0, 1)
Tool.GripUp = Vector3.new(0,1,0)
script.Parent.Handle.Break:Play()
humanoid.PlatformStand = true
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
HumanoidRootPart:ApplyImpulse(-HumanoidRootPart.CFrame.LookVector.Unit * backwardsForce)
script.Parent.Handle.Punch:Play()
wait(0.5)
script.Parent.Parent.Humanoid.Health = 0
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end)
and I get this error:
Players.ForgottenDogYT.Backpack.Goober.Handler:52: attempt to index nil with ‘CFrame’