In-game currency not working?

Hi!

My scripter has been unable to fix some of the errors with the code he produced for me so I figured perhaps someone on here may be able to help?

> local Event = game.ReplicatedStorage:WaitForChild("UpdateIslandBuxUI")
> 
> game.Players.PlayerAdded:Connect(function(player)
> 	local IslandBux = player:WaitForChild("IslandBuxValues").IslandBux.Value
> 	local function sendData(player)
> 		Event:FireClient(player,IslandBux)
> 	end
> 	sendData(player)
> 		if player:IsInGroup(3221347) then
> 			for addIslandBux = 0,-1,1 do
> 				print("Island Bux running (in group)")
> 				wait(300)
> 				IslandBux += 5
> 				sendData(player)
> 			end
> 		else 
> 			for addIslandBux = 0,-1,1 do
> 				print("Island Bux running (not in group)")
> 				wait(300)
> 				IslandBux += 10
> 				sendData(player)
> 			end
> 		end
> end)

If the player is in the group, they are supposed to receive 10 island bux per 5 minutes spent in game, whereas if they are not, they receive 5 island bux per 5 minutes.

The total remains the same regardless of the time that the player spends in game?

Thank you all in advance :slight_smile:

Problem here is that your for loop is faulty because when your 3rd expression in a for loop is a positive number but 2nd expression is smaller than the 1st one, loop simply will not run as 1st expression would be already larger than 2nd expression, thus meeting the condition to break out of the numeric for loop.

I assume you were trying to make a infinite loop here so I would suggest your to use an infinite while loop like while true do end.

Also your IslandBux increment values are wrong because according to this code it will give player 10 Island Bux when they’re not in the group, which is the opposite of you’re trying to do here.

1 Like

Change this:

local IslandBux = player:WaitForChild("IslandBuxValues").IslandBux.Value

To this:

local IslandBux = player:WaitForChild("IslandBuxValues").IslandBux

Then each instance of this:

IslandBux

To this:

IslandBux.Value
1 Like