Why is my farming script not working?

Hey,

First I want to apologize for my last topic where I just posted the long script without any context what it should do. I made a short version of the script (I realized that the long script isn’t needed afterwards)

okay so,
I’m currently working on a Tycoon/Simulator game and somehow my script is not working.

The script is supposed to make the wheats(MeshParts) invisible and give the player money for ‘‘wheats they farm’’ .

The script actually worked but suddenly it stopped working.
I think I accidentally deleted something or did something wrong

The script:

local mouse = game.Players.LocalPlayer:GetMouse()
local mouseposition = mouse.Hit.Position
local player = game.Players.LocalPlayer
local Chr = player.Character
local mon = player:WaitForChild(“DataStore”):FindFirstChild(“money”).Value
local hold = false

script.Parent.Equipped:Connect(function()
mouse.Button1Down:Connect(function()
hold = true
local tycoon = workspace.Tycoons:FindFirstChild(player.UserId)

while hold do --while button is hold 
	if tycoon then --checks for the tycoon
		if tycoon:FindFirstChild("field1") then 
			local field = tycoon:FindFirstChild("field1") 
			local fold = field:FindFirstChild("Folder")
			local wheats = fold:GetChildren()
			
			for v, i in pairs(wheats) do 
				if i and i:IsA("MeshPart") then
					local distance = (i.Position - mouseposition).Magnitude -- gets distance 
					if distance < 3 then 
						i.Transparency = 1 
						mon += 1
					end --ends if distance
				end--ends if i 
			end --ends for v,i 
   end--ends if tycoon:FindFirstChild
end--ends if tycoon

wait()
end --ends while hold
end)
end)

The script is a Local Script and in a Tool

thanks for reading and for the help in advance!

Your variable where you try to define the money value is actually just assigning the money’s value to it.
If you replace

local mon = player:WaitForChild("DataStore"):FindFirstChild("money").Value

with

local mon = player:WaitForChild("DataStore"):FindFirstChild("money")

and add .Value to the part where you add the money, it should work.

2 Likes