In my roblox game, I am making a shop gui except it does not take away gold. It will give them the extra speed as long as they have enough gold.
1 | player = script.Parent.Parent.Parent.Parent.Parent.Parent |
2 | Gold = player.leaderstats.Gold.Value |
3 | cost = 25 |
4 | script.Parent.MouseButton 1 Click:connect( function () |
5 | if Gold> = cost then |
6 | Gold = Gold - cost |
7 | player.GuardSpeed.Value = player.GuardSpeed.Value + 1 |
8 | end |
9 | end ) |
Can anyone help?
did you make a part that says leaderboardstat = leaderboardstat - cost
Alright so I went a go at it since I thought that since GuardSpeed is a value shouldn't it be in leaderstats? Also make sure that player actually goes to player. There's quite a number of parents lol.
And cost is declared, just clearing it for everyone.
01 | player = script.Parent.Parent.Parent.Parent.Parent.Parent -- Make sure this is actually leads to the 'player' |
02 |
03 | script.Parent.MouseButton 1 Click:connect( function () |
04 |
05 | local sGold = player.leaderstats [ "Gold" ] |
06 | local sGuardSpeed = player [ "GuardSpeed" ] |
07 | local sCost = 25 ; |
08 |
09 | if sGold.Value > = sCost then |
10 | sGold.Value = sGold.Value - sCost |
11 | sGuardSpeed.Value = sGuardSpeed.Value + 1 |
12 | print ( 'Purchased speed thingy' ) |
13 | else print ( 'Insufficient funds' ) |
14 | end |
15 | end ) |
EDIT: Removed leaderstat value from GuardSpeed.