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

How can i make a x2 Coins event? (where you get double coins)

I have no idea how to make this, can someone help me and explain this to me

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

local GamePassId = 10211208 -- 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)

9 comments

0

Do you mean like when you pick up a coin it give you a double when event?

0

yes

0

i can do it

0

wait 1 hour

0

i still have something to do

0

ok, thanks!

0

no problem :D

0

There you are :D, Sorry if its not working! Comment on it if its not working!!!

0

Use :Connect instead of :connect, as it is deprecated

1 answer

Hello.

The issue that you are facing is that in the script you are checking if the leaderstats do not exist, and same with the coins. Since you have this line in the code, anything that's below that line of code will not run as long as you have the leaderstats existing.

With that said, also make sure you have the correct leaderstats script to utilise this script. In your case, you can use something as simple as this for the leaderstats:

local Players = game:GetService("Players")

local function SetupLeaderstats(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Parent = leaderstats
end

Players.PlayerAdded:Connect(SetupLeaderstats)

Afterwards, you can then update your code to the following edited code to make the Double Coins gamepass function correctly, and doubling the amount of coins that you would obtain without a gamepass (10) and double it to 20 if you have the gamepass.

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

local GamePassId = 10211208
local RespawnTime = 13

local Reward = 10
local Collected = false

local function CoinTouched(ObjectCollided)
	if (ObjectCollided.Parent:FindFirstChild("Humanoid")) then
	local Player = Players:GetPlayerFromCharacter(ObjectCollided.Parent)
		if (Player) then
			local leaderstats = Player:FindFirstChild("leaderstats")
			local Coins = leaderstats:FindFirstChild("Coins")
			if not (Collected) then
				Collected = true
				if not (MarketPlaceService: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

script.Parent.Touched:Connect(CoinTouched)

Hope this helps, please comment down any issues you have with the script.

6 comments

0

thanks for the help, but i want the x2 gamepass and the x2 coin event into it (also the doube coin gamepass alr works with me just fine!)

0

Do you want the x2 Coin Event to apply for all players with no gamepass? x2 gamepass owners earn double from the event?

0

yes

0

Ah, then it's just as easy as to change the reward number from 10 to 20! This will automatically make the coin give 20 by default, and 40 to the people who own a gamepass.

0

ok.. thats easy.. wow thx

0

Glad it worked! Make sure to accept the answer so people know it's answered

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