For some reason is not changing plate

So I have this script, that you can buy a car right, so, there’s a trouble, basically, it saves the plate, but when I do SetPlate(player, vehiclemodelcloned) it doesn’t works for some reason, no errors at all, and it prints(“k”) so, any idea why it might not be working? :frowning:

game:GetService("ReplicatedStorage").BuyCar.OnServerEvent:Connect(function(Player, Item)
		if Item then
		local ItemPrice = AllItems[Item]
		print(tostring(ItemPrice))
		if not Data:GetAsync(Player.UserId.."-"..Item) then
		print(Item)
			if Player['leaderstats']['Wallet'].Value >= ItemPrice then
				Data:SetAsync(Player.UserId.."-"..Item, {Color="Black"})
				GivePlate(Player, Item)
				end
				end
			end
		end)
		local letters = {"a", "b", "c","d", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
		local numbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
		function GivePlate(plr, VehicleModel)
			local plate
			repeat
				
				plate = string.upper(letters[math.random(1, #letters)])..string.upper(letters[math.random(1, #letters)])..string.upper(letters[math.random(1, #letters)]).." "..numbers[math.random(1, #numbers)]..numbers[math.random(1, #numbers)]..numbers[math.random(1, #numbers)]
				wait()
			until not PlatesData:GetAsync(plate)
			print(plate)
			GetPlates()
			wait()
			if plate ~= nil and not table.find(GamePlates, plate) then
				table.insert(GamePlates,{Plate= plate ,Owner=plr.Name, Vehiclemodel=tostring(VehicleModel)})
				PlatesData:SetAsync("Global", GamePlates)
			end
		end
		
			

	
			function SetPlate(plr, VehicleModel)
			GetPlates()
					if VehicleModel.Model.Body.Plate then
						print("k")
						local Plate = VehicleModel.Model.Body.Plate.Plate1
						local Plate2 = VehicleModel.Model.Body.Plate.Plate2
						for i,v in ipairs(GamePlates) do
							print(v[1].." "..v[2].." "..v[3])
							if v[2] == plr.Name and v[3] == VehicleModel.Name then
								Plate.SurfaceGui.TextLabel.Text = v[1]
								Plate2.SurfaceGui.TextLabel.Text = v[1]
							end
						
					
					
				end
			end
		end

You aren’t explaining this well. What is this “plate”? What is this code trying to accomplish?

I think it gives every car a random number plate consisting of random numbers and letters. If you have already had a number plate in the past then it saves it and loads your unqiue plate that was randomly generated

image
So basically, it gives a plate, but the trouble is at SetPlate (scroll down code) and it’s not giving the plate at at all, but no errors

Any idea wait2008, I can’t sort it out yet.

What does GetPlates() do? [30 CHARS]

		function GetPlates()
    local data = PlatesData:GetAsync("Global")
if data then
	 GamePlates = data
	else
		GamePlates = {}
		end
		end

Basically, if there’s plates, then GamePlates it’s the storage of all plates.
Every time a car get’s bought, it does this:

table.insert(GamePlates,{Plate= plate ,Owner=plr.Name, Vehiclemodel=tostring(VehicleModel)})
				PlatesData:SetAsync("Global", GamePlates)

Basically saves the plates.
, I call the function just to make sure the plates get loaded before it gives the player plates, just incase

What does your output print when you use SetPlate(plr, VehicleModel)

it prints k, and then, it doesn’t prints this:

print(v[1].." "..v[2].." "..v[3])

no errors at all :man_shrugging:

My guess then is that GamePlates is empty

It shouldn’t be empty, because I save it and load it, it’s pretty weird

Looking at the get plates function, if it cant find any data it sets GamePlates to empty, have you made sure Enable Studio Access API Servers is on and is your issue happening ingame or instudio

I tried in game, and doesn’t works, api service is enabled, i’m sure, this is car spawner

I guess it’s really weird… lol

I cant really understand it but all I can mainly confirm is that GamePlates is empty, try manually setting GamePlates real quick just to make sure its the table being empty thats the problem.

I changed it manually and it doesn’t works