Farming system not working

Hello! Im making a farming system where if a player holds out a tool (Scythe) in a field, it will print “making” for every second they are in it. This is my code so far and it doesnt show any errors

local field = script.Parent
local db = true

field.Touched:Connect(function(hit)
	print(hit)
	
	
	if hit.Parent.Name == "Scythe" and db == true then
		
		local Scythe = hit.Parent
		
		while Scythe == true do
			wait(1)
			print("making")
		end
		print("caught scythe")
		db = false
		
		wait(1)
		
		db = true
		
		
		
	end
		
	
end)
3 Likes

What exactly is the problem you are running into? If you tell me what is happening vs. what you expect to happen I might be able to help.

By just looking at it I can’t really help so you should specify a bit more like @PleasantRobot704 said.
But I can notice 1 thing, try this:

local field = script.Parent
local db = true

field.Touched:Connect(function(hit)
	print(hit)
	
	
	if hit.Parent.Name == "Scythe" and db == true then
		
		local Scythe = hit.Parent
		
		while db == true do
			task.wait(1)
			print("making")
		end
		print("caught scythe")
		db = false
		
		task.wait(1)
		
		db = true
		
		
		
	end
		
	
end)

Your code over here doesn’t make much sense tho…

I didn’t fully understand you, but I think you want to make it so that when the scythe touches the grass, you have it write cyclically “making” until it becomes touching (thus ending the cycle)

If that’s what I was thinking.
Then you should try this:

local field = script.Parent
local db = true

field.Touched:Connect(function(hit)
	print(hit)

	if hit.Parent.Name == "Scythe" and db == true then

		local Scythe = hit.Parent
		
		print("caught scythe")
		db = false
		
		repeat task.wait()
			wait(1)
			if hit.Parent.Name == "Scythe" then
				print("making")
			end
		until hit.Parent.Name ~= "Scythe"
		
		db = true
		
	end
	
end)
1 Like