Uno Problem With Color and Number

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want it to always know the correct previous color and card
  2. What is the issue? Include screenshots / videos if possible!
    The problem is that sometimes the previous number and/or previous color don’t match for both players that are playing.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

GameTurnEvent.OnClientEvent:Connect(function(NextPlayer)
	print(NextPlayer)
	print("Next Player Is" .. tostring(NextPlayer)) 
	
	print("Previous Card is".. tostring(PreviousCard))
	
	 if string.find(PreviousCard.Name, "Red") then
        PreviousCardColour = "Red"
    elseif string.find(PreviousCard.Name, "Yellow") then
        PreviousCardColour = "Yellow"
    elseif string.find(PreviousCard.Name, "Blue") then
        PreviousCardColour = "Blue"
    elseif string.find(PreviousCard.Name, "Green") then
        PreviousCardColour = "Green"
	end
	
	-- CHECKING THE NUMBER OF THE PREVIOUS CARD --
	
	if string.find(PreviousCard.Name, "0") then
		print("Previous")
		PreviousCardNumber = 0
	elseif string.find(PreviousCard.Name, "1") then
		print("Previous")
		PreviousCardNumber = 1
	elseif string.find(PreviousCard.Name, "2") then
		print("Previous")
		PreviousCardNumber = 2
	elseif string.find(PreviousCard.Name, "3") then
		print("Previous")
		PreviousCardNumber = 3
	elseif string.find(PreviousCard.Name, "4") then
		print("Previous")
		PreviousCardNumber = 4
	elseif string.find(PreviousCard.Name, "5") then
		print("Previous")
		PreviousCardNumber = 5
	elseif string.find(PreviousCard.Name, "6") then
		print("Previous")
		PreviousCardNumber = 6
	elseif string.find(PreviousCard.Name, "7") then
		print("Previous")
		PreviousCardNumber = 7
	elseif string.find(PreviousCard.Name, "8") then
		print("Previous")
		PreviousCardNumber = 8
	elseif string.find(PreviousCard.Name, "9") then
		print("Previous")
		PreviousCardNumber = 9
	end

	print(PreviousCardColour)
	print(PreviousCardNumber)
	
	----------------------------------- MAIN SCRIPT -----------------------------------
	
	local CardThrowCooldown = false
	local TurnEnded = false

	for i, C in ipairs(UnchangableCardsArray) do
		
		C.MouseButton1Click:Connect(function()
			
			print("ClickedCard is".. tostring(C))
			
			-- GETTING THE ATTRIBUTES OF THE CURRENT CARD --
			
			local PressedCardColour = C:GetAttribute("Colour") 
			local PressedCardNumber = C:GetAttribute("Number") 
			local Plus2 = C:GetAttribute("Plus2")
			local Plus4 = C:GetAttribute("Plus4")
			local ColourChange = C:GetAttribute("ColourChange")
			local Reverse = C:GetAttribute("Reverse")
			local Skip = C:GetAttribute("Skip")

			-------------------------------------------------

			print("Pressed Card CLOUR IS " .. tostring(PressedCardColour))
			print("Pressed Card NUMBER IS " .. tostring(PressedCardNumber))
			print("Previous Card CLOUR IS " .. tostring(PreviousCardColour))
			print("Previous card number is " .. tostring(PreviousCardNumber))
			
			if Plus4 and not TurnEnded then
				
				print("Plus4")
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C, NextPlayer)			
				PreviousCard = C
				C:Destroy()			

			
			elseif ColourChange and not TurnEnded then
				
				print("ColourChange")
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C)			
				PreviousCard = C
				C:Destroy()
	
				
			elseif Reverse and PreviousCardColour == PressedCardColour and not TurnEnded then 
					
				print("Reverse")
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C)			
				PreviousCard = C
				C:Destroy()
				
					
			elseif Skip and PreviousCardColour == PressedCardColour and not TurnEnded then
					
				print("Skip")	
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C)			
				PreviousCard = C
				C:Destroy()
				
						
			elseif Plus2 and PreviousCardColour == PressedCardColour and not TurnEnded then						
					
				print("Plus2")	
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C)			
				PreviousCard = C
				C:Destroy()

				
			elseif PreviousCardColour == PressedCardColour and not TurnEnded then	
				print("NormalCard")	
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C)			
				PreviousCard = C
				C:Destroy()

				
			elseif PreviousCardNumber == PressedCardNumber and not TurnEnded then
				print(PressedCardNumber, PreviousCardNumber)
				print("NormalCard")	
				TurnEnded = true
				ThrowCardAnimationEvent:FireServer(C)			
				PreviousCard = C
				C:Destroy()
			end	
		end)
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

So you say the previous color and number don’t match, which client shows the correct information and which one is incorrect? Also, I would do a bit more of a format to your cards, maybe just name them Red0 or Blue9. You can then grab the last character and use that as the number, and everything up until the last character as the color. Your code is much longer than it needs to be.