Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a x2 coins gamepass with this code?

So i have been wondering how to make a x2 coins gamepass and i need help, can i integrate a x2 coins gamepass with this code?

waittime = 13 -- Time Between each hit
amnt = 10 --how much you get for it
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Coins")
				if (score~=nil) then
					score.Value = score.Value + amnt
				end
			end
		end

		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
		script.Disabled = true
		wait(waittime)
		script.Parent.Transparency = 0
		script.Parent.CanCollide = true
		script.Disabled = false		


	end
end

script.Parent.Touched:connect(onTouched)

4 comments

0

Line 19 tho

0

I would use a debounce instead of doing script.Disabled just in case it causes any problems. Other than that i think it would work fine. Also, I would make a base amount to give the player and then do an if statement to check if the player had the gamepass and if they do, amnt = amnt * 2, this could make your code easier to manage.

0

You must use a debounce. Disabling the Script will require second-hand reactivation. You can also just set up a Ternary using MarketplaceService's 'UserOwnsGamePassAsync' Boolean to bias amount or amount * 2.

0

i have no idea how to script, my friend came up with this and he cant help me with the x2 coins game pass thing so i came here for some help

1 answer

✓ Accepted answer

I edited your code a little bit and this should work, all you need to do is get your gamepass id and change it to 'GamePassId'

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local GamePassId = 15200883 -- your gamepass id here
local RespawnTime = 13
local Reward = 10
local Collected = false

function Touch(object)
	if object.Parent:FindFirstChild("Humanoid") then
		if Players:GetPlayerFromCharacter(object.Parent) then
			local Player = Players:GetPlayerFromCharacter(object.Parent)
			local leaderstats = Player:FindFirstChild("leaderstats")
			local Coins = leaderstats:FindFirstChild("Coins")
			if leaderstats ~= nil and Coins ~= nil then
				if not Collected then
					Collected = true
					if not MPS:UserOwnsGamePassAsync(Player.UserId, GamePassId) then
						Coins.Value += Reward
					else
						Coins.Value += Reward *2
					end
					script.Parent.Transparency = 1
					script.Parent.CanCollide = false
					wait(RespawnTime)
					script.Parent.Transparency = 0
					script.Parent.CanCollide = true
					Collected = false
				end
			end
		end
	end
end

script.Parent.Touched:connect(Touch)

1 comment

0

Thanks for the help,i have been struggling so much to make one!

This discussion is preserved as it was. New answers, comments, and votes are closed.