So I have a coin script that gives you one coin when you step on it. I made a gamepass you can buy where you get 3 coins every time you step on a coin. (A coin trippler). Although I get 9 coins instead of 3.
01 | local db = true |
02 | local passId = 297078187 |
03 |
04 | script.Parent.Touched:connect( function (obj) |
05 | local player = game.Players:FindFirstChild(obj.Parent.Name) |
06 | if player and db then |
07 | db = false |
08 | local coins = player.leaderstats.Coins |
09 | workspace.Sounds.CoinSound:Play() |
10 | for i = 0 , 1 , . 1 do |
11 | script.Parent.Transparency = i |
12 | wait() |
13 | end |
14 | local coins = player.leaderstats.Coins |
15 | if game:GetService( "MarketplaceService" ):PlayerOwnsAsset(player, passId) then |
Any idea how this happens? Thanks.
You should've done local db = false I also Reccomend WaitForChild()
01 | local db = false |
02 | local passId = 297078187 |
03 |
04 | script.Parent.Touched:connect( function (obj) |
05 | local player = game.Players:GetPlayerFromCharacter(obj) |
06 | if player and db = = false then |
07 | db = true |
08 | local coins = player.leaderstats.Coins |
09 | workspace.Sounds.CoinSound:Play() |
10 | for i = 0 , 1 , 0.1 do |
11 | script.Parent.Transparency = i |
12 | wait() |
13 | end |
14 | --local coins = player.leaderstats.Coins Why declare the same variable twice?? |
15 | if game:GetService( "MarketplaceService" ):PlayerOwnsAsset(player, passId) then |
Hopefully this would help you in this script :)