Code is not work again

At the end of the code I set the waitt variable to ‘false’ again, it should work again but it doesn’t.

part.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local playerId = player.UserId
	if waitt == false then
		print("cliked")
		waitt = true
		
		local success, honey = pcall(function()
			return bee_data:GetAsync("honey" ..playerId)
		end)
		
		if honey == 1 then
			local success, currentGold = pcall(function()
				return bee_data:GetAsync("sıra" ..playerId)
			end)
			local location_part = workspace.Tycoon.Bir_Sira:WaitForChild("" ..currentGold)
			local dropper = ServerStorage:WaitForChild("Dropper")
			local clonedmodel = dropper:Clone()
			wait(1)
			clonedmodel.Parent = workspace
			clonedmodel:PivotTo(location_part.CFrame)
			if clonedmodel:PivotTo(location_part.CFrame) then
				waitt = false
			end
		end
	end
end)
1 Like

Maybe try remove the if statement?
(also did some stuff so it should hopefully work)

part.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local playerId = player.UserId
	if not waitt then --doing waitt==false is the same as "not wait"
		print("cliked")
		waitt = true
		
		local success, honey = pcall(function()
			return bee_data:GetAsync("honey" ..playerId)
		end)
		
		if honey == 1 and success then
			local success1, currentGold = pcall(function()
				return bee_data:GetAsync("sıra" ..playerId)
			end)
			local location_part = workspace.Tycoon.Bir_Sira:WaitForChild("" ..currentGold)
			local dropper = ServerStorage:WaitForChild("Dropper")
			local clonedmodel = dropper:Clone()
			wait(1)
			clonedmodel.Parent = workspace
			clonedmodel:PivotTo(location_part.CFrame)
		        waitt = false
                else
                      warn("something went wrong (very informative)")
		end
	end
end)

You only set it if if clonedmodel:PivotTo(location_part.CFrame) is true, but it won’t work if the decimal of the CFrame is off by .000001 studs.

If you need that you should round both CFrames to 1 or 2 decimal places and then compare them.

1 Like

it messed up indentations for some reason but it should still work

Oh okay, then i do this and worked:

part.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local playerId = player.UserId
	if waitt == false then
		print("cliked wait false")
		waitt = true
		
		local success, honey = pcall(function()
			return bee_data:GetAsync("honey" ..playerId)
		end)
		
		if honey == 1 then
			local success, currentGold = pcall(function()
				return bee_data:GetAsync("sıra" ..playerId)
			end)
			local location_part = workspace.Tycoon.Bir_Sira:WaitForChild("" ..currentGold)
			local dropper = ServerStorage:WaitForChild("Dropper")
			local clonedmodel = dropper:Clone()
			wait(1)
			clonedmodel.Parent = workspace
			clonedmodel:PivotTo(location_part.CFrame)
			waitt = false
		end
	end
end)
1 Like

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