Help with making animated coins!

Hello! I’m currently making a coins system with some nice animation. All players that won will get coins. The coins and animation are working perfectly fine but the problem is when the coins are given, one player is getting them then the other one is getting them later.
Here’s the video because i can’t explain it:

In the video, first player got coins and the other player must wait for the first player coins. I want to give coins to all player at the same time.

I tried to search posts on the forum but nothing helped me.

I can always share my code if someone would like to help me!

2 Likes

Please give us the script you are using and put 3 backticks (```) before and after it so it formats properly.

It looks like the loop you have to add coins is running through each player individually.
Instead you should have a loop to add all players who receive a coin into a table, then a loop inside the first loop to add a coin to each player inside the table.

2 Likes
local coinstable = {20, 19, 15, 17, 23}

game.ReplicatedStorage.Status:GetPropertyChangedSignal("Value"):Connect(function()
	if game.ReplicatedStorage.Status.Value == "Game Ended!" and game.ReplicatedStorage.GameValues.Spinner.Value == true then
		game.ReplicatedStorage.GameValues.Spinner.Value = false
		for _,player in pairs(game.Players:GetPlayers()) do
			local char = player.Character

			if player.Team.Name == "Game" then
				player.leaderstats.Wins.Value += 1
				player.Team = game.Teams.Lobby
				char.HumanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame 
				local random = math.random(5)
				local choosen = coinstable[random]
				
				for i = choosen,0,-1 do
					game.ReplicatedStorage.CoinsSound:FireClient(player)
					player.CoinsFolder.Coins.Value += 1
					player.PlayerGui.CoinsGui.Frame.TextLabel:TweenSizeAndPosition(UDim2.new(0.215, 0,0.454, 0),UDim2.new(0.148, 0,0.442, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,0.05)
					wait(0.05)
					player.PlayerGui.CoinsGui.Frame.TextLabel:TweenSizeAndPosition(UDim2.new(0.179, 0,0.501, 0),UDim2.new(0.179, 0,0.347, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,0.05)
					wait(0.05)
				end
				player.PlayerGui.CoinsGui.Frame.TextLabel:TweenSizeAndPosition(UDim2.new(0.215, 0,0.454, 0),UDim2.new(0.148, 0,0.422, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,0.1)
			else
				player.leaderstats.Wins.Value += 0
			end
		end
		for _,v in pairs(script.Parent.Cube:GetChildren()) do
			if v:IsA("SurfaceGui") then
				v.Enabled = false
			end
		end
	end
end)

I know this script looks really messed up (im not a professional coder)

1 Like

See my notes in the code:

		for _,player in pairs(game.Players:GetPlayers()) do
			local char = player.Character -- here you get only one player

			if player.Team.Name == "Game" then
				player.leaderstats.Wins.Value += 1
				player.Team = game.Teams.Lobby
				char.HumanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame 
				local random = math.random(5)
				local choosen = coinstable[random]
				
				for i = choosen,0,-1 do
					game.ReplicatedStorage.CoinsSound:FireClient(player)
					player.CoinsFolder.Coins.Value += 1  -- here you add coins only to the player above.

  -- GUI code stuff

			else
				player.leaderstats.Wins.Value += 0
			end
		end
1 Like

the code still looks the same. did you change anything or im blind? (still the same bug occurs)

1 Like

I didn’t change anything, I just added notes to explain why your code is doing what it’s doing.

My first post explains what I thought was the issue with your code. If you follow the recommendations there about the loops it should work the way you want it to.

But that’s really my issue. I don’t know how to do it, that’s why i posted here

1 Like