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)
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
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