Issue with tycoon drop processor

So I have this script:

for i,v in pairs(script.Parent.Essentials:GetChildren()) do
		local Owner = script.Parent.Owner
		if v.Name == "PartCollector" then
			v.Touched:connect(function(Part)
				if Part:FindFirstChild('Cash') then
					if Owner.Value ~= nil then
						local player = Owner.Value
						local gamepasses = player:WaitForChild("Gamepasses")
						
						if gamepasses["Auto Collect Cash"].Value == true then
							local playerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if playerMoney ~= nil then
								playerMoney.Value = playerMoney.Value + (Part.Cash.Value * gamepasses.Cash.Value)
							end
						elseif gamepasses["Auto Collect Cash"].Value == false then
							Money.Value = Money.Value + (Part.Cash.Value * gamepasses.Cash.Value)
							Debris:AddItem(Part,0.1)
						end
					end
				end
			end)
		end
	end

And it isn’t working.

The collector will collect stuff, but it won’t add to my CurrencyToCollect value. I think the gamepasses variable is not working, but correct me if I am wrong.

If you find the place that makes the script not work, please let me know!


Notes:

  • the Money variable is
local Money = script.Parent.CurrencyToCollect
1 Like

Can you show the game output ? So we can see the error.

Btw you shouldn’t look for gamepass that way, you wrote player:FindFirstChild(“Gamepasses”) wich is I think wrong

At the start of the script you should write
gamepass = game:GetService(“MarketPlaceService”)
And instead of :
player:FindFirstChild(“Gamepasses”)
if gamepasses[“AutoCollect Cash”].Value == true then
You should write :
if gamepass:UserOwnsGamePassAsync(player.UserId,GamepassID) then

First off, I wrote

:WaitForChild not :FindFirstChild

Second, there is a game passes folder that holds everything needed for gamepasses. There is already a script that handles every game pass.

EDIT: there are no errors in the output

If you aren’t receiving any errors in the output then it would help to add print statements around your code to isolate a source of error for us to be able to help you in the first place, either to confirm the existence or value of something or that points of your code are getting reached. The most that can be done here is guessing and assuming which is not very productive.

3 Likes

Just try to edit this code which you can find in the purchase handler
Line 41-63

It seems like the owner is found, and so is the player.
Screen Shot 2020-03-31 at 5.47.07 PM
Only problem is, the collector won’t collect. Here is my code:

for i,v in pairs(script.Parent.Essentials:GetChildren()) do
		local Owner = script.Parent.Owner
		if v.Name == "PartCollector" then
			v.Touched:connect(function(Part)
				if Part:FindFirstChild('Cash') then
					if Owner.Value ~= nil then
						print("Owner found")
						local player = Owner.Value
						local gamepasses = player:WaitForChild("Gamepasses")
						
						if player and gamepasses["Auto Collect Cash"].Value == true then
							print(player.Name.." was found, and the gamepass' value is true")
							local playerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if playerMoney ~= nil then
								playerMoney.Value = playerMoney.Value + (Part.Cash.Value * gamepasses.Cash.Value)
							else
								error("Player's money was not found")
							end
						elseif player and gamepasses["Auto Collect Cash"].Value == false then
							print(player.Name.." was found, and the gamepass' value is false")
							Money.Value = Money.Value + (Part.Cash.Value * gamepasses.Cash.Value)
							Debris:AddItem(Part,0.1)
						elseif not player then
							error("Could not find the player")
						end
					else
						error("Owner not found")
					end
				end
			end)
		end
	end

I did not have the gamepass bool value set to true. Just remember, the Money variable is the CurrencyToCollect value.

@Anton00k oh, I think you thought of the thing where you collect the money. It’s the processor that I’m talking about, the code right above those lines.

What is stored inside the gamepasses instance? Is there a cash value inside that instance?

That made me wonder. I just noticed this, but the values are all set to 0, but if you have a gamepass the value goes up 2. That is why no cash is earned even though the collector collects it.

Interesting… perhaps checking for the scripts that adjusts those values would help.

1 Like

Yes I found it. The gamepass handler didn’t do anything to the values unless you had the gamepass. I tested it out with the value at 1 and it worked. When I tested it with 1 billion, it errored.

So it’s working now? Or is there any errors?

1 Like

It works, I’m just trying to find out something else now. I’ve found a solution!

Do you need help with whatever you are trying to fix? If not, then please check the box “Solution” on the reply that helped you solve it, so others know that this post was solved and answered

Just made a new topic regarding this.

1 Like