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