2 Problems with tycoon (Problem1 Fixed)

I’ve made a tycoon before though the dropped item were parts, not models.

Problem 2: The models won’t sell when they hit the depoist part (Sell part) at the end of the conveyor.

Script:

local tycoon = script.Parent.Parent
local deposit = script.Parent
local objectsFolder = tycoon.Objects

local function addPoints(points)
	local player = tycoon.TycoonOwner.Value

	if player then
		local money = player.leaderstats.Money
		money.Value = money.Value + points
	end
end

local function sellObject(part)
	if part.Name == "Water pistol" then
		addPoints(1)
	
		end
	end

	part:Destroy()
end

local function onTouched(otherPart)
	if otherPart.Parent == objectsFolder then
		sellObject(otherPart)
	end
end

deposit.Touched:Connect(onTouched)

Try to change the parent first and then use MoveTo() also the warning says CanTouch is disabled which means the touched event will not work so enable it.

Thats a different button, for the other buttons that are invisible.

If the value is something like the player’s name, it must refer to the player’s object.

local function addPoints(points)
	local player = tycoon.TycoonOwner.Value
    local playerObject = game.Players:FindFirstChild(player)
	if player and playerObject then
		local money = playerObject.leaderstats.Money
		money.Value = money.Value + points
	end
end

Didn’t work. I don’t think there is an issue with the player because my script worked on a different tycoon. Maybe its because the thing being sold is a model?

Yes, that should be the problem. Because the first parameter of the Touched event is the part that touched it, not the model. If you want to get the model name, you can get it from the parent of the part.

So I tried this. Though it didn’t work. Was this script what you were thinking of?

local tycoon = script.Parent.Parent
local deposit = script.Parent
local objectsFolder = tycoon.Objects
local Pistol = game.ReplicatedStorage["Water pistol"]

local function addPoints(points)
	local player = tycoon.TycoonOwner.Value
	local playerObject = game.Players:FindFirstChild(player)
	if player and playerObject then
		local money = playerObject.leaderstats.Money
		money.Value = money.Value + points
	end
end

local function sellObject(Part)
	local model = Pistol
	
	if model.Name == "Water pistol" then
		addPoints(1)

		end
	end

	model:Destroy()
end

local function onTouched(otherPart)
	if otherPart.Parent == objectsFolder then
		sellObject(otherPart)
	end
end

deposit.Touched:Connect(onTouched)

No, I was referring to the sellObject function.

Maybe this should work:

local function sellObject(part)
	if part.Parent.Name == "Water pistol" then
		addPoints(1)

		end
		part.Parent:Destroy()
end
end

Didn’t work. I don’t know what the issue is. Maybe we didn’t properly define part?

Got any ideas on what is wrong?