Everything in the script is Fine…
Until I die then I get this error I’m very new to scripting and this is my first Dev Forum post so feedback to make this clearer will be helpful
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Frame = player.PlayerGui.EatFruitGui.Main
local Yes = Frame.Yes
local No = Frame.No
local EatAnim = script:WaitForChild("Eat")
local EatAnimTrack = humanoid.Animator:LoadAnimation(EatAnim)
local DevilFruits = game.ReplicatedStorage.DevilFruits
local currentTool = script.Parent
local Toolname = "Rubber"
local function boop(Player)
Frame.Visible = true
local character = currentTool.Parent
local playerWhoEquippedTool = game.Players:GetPlayerFromCharacter(character)
Yes.MouseButton1Click:wait()
EatAnimTrack:Play()
humanoid.WalkSpeed = 0
wait(3.5)
script.Parent:Destroy()
if not playerWhoEquippedTool.Backpack:FindFirstChild(Toolname) then
local Tool = game.ReplicatedStorage.DevilFruits[Toolname]:clone()
Tool.Parent = playerWhoEquippedTool.Backpack
humanoid.WalkSpeed = 16
else
No.MouseButton1Click:wait()
end
end
currentTool.Activated:Connect(boop)
The error line is Line 10 Which is - local EatAnimTrack = humanoid.Animator:LoadAnimation(EatAnim)
So you get this error if the animation is being played while the player is dead. The easiest way to avoid this is to run a if statement to check if the player is dead. In your case that would look like:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local Frame = player.PlayerGui.EatFruitGui.Main
local Yes = Frame.Yes
local No = Frame.No
local EatAnim = script:WaitForChild(“Eat”)
local EatAnimTrack = humanoid.Animator:LoadAnimation(EatAnim)
local DevilFruits = game.ReplicatedStorage.DevilFruits
local currentTool = script.Parent
local Toolname = “Rubber”
local function boop(Player)
if player.Character.Humanoid.Health > 0 then
Frame.Visible = true
local character = currentTool.Parent
local playerWhoEquippedTool = game.Players:GetPlayerFromCharacter(character)
Yes.MouseButton1Click:wait()
EatAnimTrack:Play()
humanoid.WalkSpeed = 0
wait(3.5)
script.Parent:Destroy()
if not playerWhoEquippedTool.Backpack:FindFirstChild(Toolname) then
local Tool = game.ReplicatedStorage.DevilFruits[Toolname]:clone()
Tool.Parent = playerWhoEquippedTool.Backpack
humanoid.WalkSpeed = 16
else
No.MouseButton1Click:wait()