Potion gets stuck mid animation

I made a potion that makes the player move faster after drinking. I made the model for the bottle myself and pretty much copied the code from the classic bloxy cola for the animation of drinking it. For some reason, when I unequipped the potion in the middle of the animation and waited for the sound to finish, the potion got stuck in the same position and I couldn’t use it anymore.

Video:

This is strange because the bloxy cola doesn’t break like this, even if unequipping it mid animation. I tried looking at the code to see the problem but they’re both very similar and I haven’t figured out what it could be.

Bloxy Cola:

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.5,-.5,.3)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(3)
	
	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.MaxHealth > h.Health + 5) then
			h.Health = h.Health + 5
		else	
			h.Health = h.MaxHealth
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

Blue Potion:

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.4,-.5,.10)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(3)

	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.JumpHeight == 20) then
			h.JumpHeight = 7.2
		end
	end
	
	h.WalkSpeed = 50

	Tool.GripForward = Vector3.new(0,0,0)
	Tool.GripPos = Vector3.new(0,0,0)
	Tool.GripRight = Vector3.new(0,0,0)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

I don’t know if it matters but the bloxy cola is a mesh and the potion was made using a model with a bunch of weld constraints.

How do I fix this and prevent it from breaking?

Dont know why this happens to me too but heres a fixed version of your blue potion script.

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.4,-.5,.10)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(3)

	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.JumpHeight == 20) then
			h.JumpHeight = 7.2
		end
	end

	h.WalkSpeed = 50

	Tool.GripForward = Vector3.new(0,0,0)
	Tool.GripPos = Vector3.new(0,0,0)
	Tool.GripRight = Vector3.new(0,0,0)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end

function unEquipped()
	Tool.GripForward = Vector3.new(0,0,0)
	Tool.GripPos = Vector3.new(0,0,0)
	Tool.GripRight = Vector3.new(0,0,0)
	Tool.GripUp = Vector3.new(0,1,0)
end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(unEquipped)
1 Like

I figured out the problem and I feel stupid for not checking my output. Every time I was unequipping my potion mid animation, it was trying to index nil with walk speed.


I simply moved the code that changed the walk speed to inside the check if h ~= nil.

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.4,-.5,.10)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(1)

	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		h.WalkSpeed = 50
		if (h.JumpHeight == 20) then
			h.JumpHeight = 7.2
		end
	end
	

	Tool.GripForward = Vector3.new(0,0,0)
	Tool.GripPos = Vector3.new(0,0,0)
	Tool.GripRight = Vector3.new(0,0,0)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end


function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)