Scripting help needed

I’m making a skateboard tool and it spawns a skateboard, but it doesn’t spawn if I unequip and equip it again.

Video if needed:

My script:

local canClick = true
local timer = 60
local skateboard

script.Parent.Activated:Connect(function()
	if canClick then
		canClick = false
		skateboard = game.ReplicatedStorage:FindFirstChild("SkateBoard"):Clone()
		if skateboard then
			print("skateboard spawned!")
			skateboard.Mesh.Position = script.Parent.Parent.Torso.Position - Vector3.new(0, 3, 0)
			skateboard.Mesh.Orientation = Vector3.new(0, 180, 0)
			skateboard.Parent = script.Parent.Parent
			local weld = Instance.new("WeldConstraint", skateboard)
			weld.Part0 = skateboard.Mesh
			weld.Part1 = script.Parent.Parent.Torso
			skateboard.Mesh.Anchored = false
			timer = 60
			while task.wait(0.01) do
				timer -= 1
				skateboard.Mesh.Orientation = script.Parent.Parent.HumanoidRootPart.Orientation
				if timer == 0 or timer < 1 then
					break
				end
			end
		end
	end
end)


script.Parent.Unequipped:Connect(function()
	skateboard:Destroy()
end)

Where do you set canClick back to true? It looks like that doesn’t happen, try adding that to the Unequipped event:

script.Parent.Unequipped:Connect(function()
	canClick = true
	skateboard:Destroy()
end)
local canClick = true
local skateboard

script.Parent.Activated:Connect(function()
	if canClick then
		canClick = false
		skateboard = game.ReplicatedStorage:FindFirstChild("SkateBoard"):Clone()
		if skateboard then
			print("skateboard spawned!")
			skateboard.Mesh.Position = script.Parent.Parent.Torso.Position - Vector3.new(0, 3, 0)
			skateboard.Mesh.Orientation = Vector3.new(0, 180, 0)
			skateboard.Parent = script.Parent.Parent
			local weld = Instance.new("WeldConstraint", skateboard)
			weld.Part0 = skateboard.Mesh
			weld.Part1 = script.Parent.Parent.Torso
			skateboard.Mesh.Anchored = false
			spawn(function()
				for i = 1,60 do
					wait(1)
					if skateboard then
						skateboard.Mesh.Orientation = script.Parent.Parent.HumanoidRootPart.Orientation
					end
				end
			end)
		end
	end
end)


script.Parent.Unequipped:Connect(function()
	skateboard:Destroy()
end)

An error may occur because the while loop returns

1 Like

oh yeah, i forgot about that. I’ll try to see if that will fix it, thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.