I am currently working on gamepasses for my tycoon and was wondering if anyone had references to help me make an auto collector and 2x cash gamepass.
Current Cash function:
local Debounce = false
Mainitems.CashButton.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == player then
if Debounce == false then
Debounce = true
player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
end
end
end
end)
while wait() do
Mainitems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end
It seems like you’re using GamerM8’s tutorial, aren’t you ?
yes as a template. I altered most of the other code.
local Debounce = false
local MPS = game:GetService("MarketplaceService")
Mainitems.CashButton.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == player then
if Debounce == false then
Debounce = true
if MPS:UserOwnsGamepassAsync(player.UserId, gamepassidhere) then
player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value * 2
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
else
player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
end
end
end
end
end)
while wait() do
Mainitems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end
Hey, try the above code and tell me if it works or not!
I should have mentioned that I created separate buttons for each gamepass.
Wont let me collect from the collector.
Its also not doubling the tix with the gamepass
What do you mean ? You mean you can’t collect it when you touch the collector ? Also, when you try to collect, does it have some money ? Do you have any errors, if yes, show me please, also show your whole code.
Correct. It does not double the currency and the collector breaks.
Error: UserOwnsGamepassAsync is not a valid member of MarketplaceService “MarketplaceService” - Server - MainScript:119
Oh, there’s error in the syntax of UserOwnsGamepassAsync, try checking developer hub or lemme check and recorrect it.
Updated code, it should work -
local Debounce = false
local MPS = game:GetService("MarketplaceService")
Mainitems.CashButton.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == player then
if Debounce == false then
Debounce = true
if MPS:UserOwnsGamePassAsync(player.UserId, gamepassidhere) then
player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value * 2
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
else
player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
end
end
end
end
end)
while wait() do
Mainitems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end
not a good idea to check if the player owns the gamepass each time, best to check on player join, and save that view a attribute/value, and then read from that value instead.
Lemme explain why this idea isn’t good. See, once the player joins, you need to use DataStores to load the data, which may glitch sometime and it also takes time to load. Another way is to use :UserOwnsGamePassAsync, but still we are using it here. Now suppose he has 10 gamepasses, it would be kind of messed. I don’t see any demerit of my code. UserOwnsGamePassAsync also returns true or false and attribute would also give a bool value. So I don’t see anything wrong. Also, he needs to go deep in DataSaving.
How old is this snippet?? Why are you using a while loop to change a text, Despite 5 connections existing?
I didn’t used, I just gave OP the idea, it’s written by OP. I just didn’t change it.
local CollectionService = game:GetService("CollectionService")
local Market = game:GetService("MarketplaceService")
Mainitems.CashButton.ButtonPart.Touched:Connect(function(Hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Player ~= nil then
if Values.OwnersValue.Value == Player then
if not CollectionService:HasTag(Player, "CDTC") then
CollectionService:AddTag(Player, "CDTC")
task.delay(1,function()
CollectionService:RemoveTag(Player, "CDTC")
end)
if Market:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
Player.leaderstats.Tix.Value += Values.CashValue.Value * 2
else
Player.leaderstats.Tix.Value += Values.CashValue.Value
end
task.wait(0.03)
Values.CashValue.Value = 0
end
end
end
end)
Values.CashValue.Changed:Connect(function(Value)
Mainitems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Value
end)
Why did you even used CollectionService here though ???
How is it related to a gamepass ?
Cooldown? I just replaced it with the debounce boolean cooldown?
Can’t you just use a variable for debounce ? What’s the advantage for using CollectionService just for a debounce ?
Just for clarity
If you think I’m angry, I ain’t, just for understanding things, I’m asking.