Problem With Tycoon Sell Script

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

Problem: The models won’t sell when they hit the deposit 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
	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)
	if part.Parent.Name == "Water pistol" then
		addPoints(1)

	end
	part.Parent:Destroy()
end




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

deposit.Touched:Connect(onTouched)

There is an extra end right here

Umm can you please tell me where?

oh, it didn’t show the part where I had quoted, fixed it.

1 Like

That was my mistake I typed it wrong on DevForum

Well, the script should work fine? Can you show me the tycoon folder/model?

We I tested it and it doesn’t idk why also i will ask my dev to provide that

Ye hi i’m the other dev working on the tycoon, and could you clerify?

Im asking for a screenshot of the tycoon model/folder. Also, please give any errors in the output

There are no error in the output. Here is a screenshot of what is happening. The models are just clumping up at the end.

is this what you meant?

not what I mean, I’m talking about the explorer lol.
Edit: Oh, just noticed this, but the problem could be in 2 areas.

Right here, you check if the part’s parent is the ObjectsFolder and will only activate the sell function if it is. I’m assuming its not selling because of this, but it could also be this

Here you check if the parent’s name is “Water pistol” making me assume the parent will either be this or the ObjectFolder, but since it isn’t being destroyed, I assume it is the latter. To fix this, change the function to this:

local function onTouched(otherPart)
	if otherPart.Parent.Parent == objectsFolder then --Added an extra parent
		sellObject(otherPart)
	end
end

oh sorry.

To make it bigger right click and click open image in new tab

Well, pretty sure I figured it out in my last post’s edit, so check that out and see if either of them are the problem.

2 Likes

Still doesn’t work. Though there is an error in the output:
Workspace.Tycoon.DepositPart.Deposit:29: attempt to index nil with ‘Parent’
Sorry I couldn’t get back to you sooner I had to go somewhere

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


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)
	if part.Parent.Name == "Water pistol" then
		addPoints(1)

	end
	part.Parent:Destroy()
end




local function onTouched(otherPart)
	if otherPart.Parent.Parent == objectsFolder then --Added an extra parent
		sellObject(otherPart)
	end
end

deposit.Touched:Connect(onTouched)

Alright, this should be caused by it being touched by a part that is directly under the workspace, leading to the second parent being nil. To fix this, I would use :IsDescendantOf()

local function onTouched(otherPart)
	if otherPart:IsDescendantOf(objectsFolder) then
		sellObject(otherPart)
	end
end
2 Likes

YAY it works! Though it didnt give any money so I used my add points script and it worked! Thank you for your help!