Script Issue, easy to fix

you told me to put carId, but where did that come from?

From the dictionary, which has its keys as the image ids, so to access the value, you have to use the key, the image id, my question is, why did you make the image id the key, and the name the value?

1 Like

I dont know, i dont understand it.

is this good or no?

local CarImage = CarImageIds[carName]
CarSpawnNotificationEvent:FireClient(CarImage)

1 Like

This doesn’t work, becasue the name is not the key, so you cannot get a value from CarImageIds[carName], additionally, the image id is the key, do you cannot get it by putting a value in, the syntax works as value = dictionary[key] and not key = dictionary[value].

You might need to read the syntax on this Intro to Dictionaries | Roblox Creator Documentation.

1 Like

so what do i do?

Also, this is there script that its attached to in a starterGUI

local script = script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CarSpawnNotificationEvent = ReplicatedStorage:WaitForChild("CarSpawnNotification")






CarSpawnNotificationEvent.OnClientEvent:Connect(function(carImage)
	CarSpawnNotificationFrame:TweenPosition(UDim2.new(0, 0,0, 0), "InOut", "Quad", 0, true)
	CarSpawnNotificationFrame.Visible = true
	local NotificationImage = script.Parent.ImageSlot.ImageLabel
	NotificationImage = carImage
end)

CarSpawnNotificationFrame.MouseButton1Click:Connect(function()
	CarSpawnNotificationFrame:TweenPosition(UDim2.new(-0.13, 0,0, 0), "InOut", "Quad", 1, true)
	wait(1)
	CarSpawnNotificationFrame.Visible = false
end)

As I said earlier, you can do one of three things:

  • swap the values and keys.
  • use a pairs loop to find a key from a value.
  • just using the image ids as the key, and the name as the value.

You can swap the keys and values in the dictionary, making you code work and make much more sense.

1 Like

You should probably just switch the id and name in the image table:

["Beige Dune Buggy"] = 6068169587

and then use carName to get the ID.

local CarImage = CarImageIds(carName)

try this, it uses table.find() to get the index:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")
local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
local CarSpawnNotificationEvent = ReplicatedStorage:WaitForChild("CarSpawnNotification")

local CarImageIds = {

	[6068169587] = "Beige Dune Buggy" ,
	[109662003] = "Black Jeep" ,
	[242143853] = "Black Sedan" ,
	[8382532839] = "Blue SUV" ,
	[126103845] = "Ford Shelby Truck" ,
	[4072026855] = "Green camo Jeep" ,
	[3142634] = "Lamborghini Aventador SVJ" ,
	[7225067642] = "Pink Jeep" ,
	[7141615506] = "Police Car" ,
	[28261053] = "Red Maserati Car" ,
	[6881212666] = "Red Sedan" ,
	[7262556994] = "White Van" ,

}







SpawnCarEvent.OnServerEvent:Connect(function(player, carName)
	local Car = ServerStorage:FindFirstChild("Cars"):FindFirstChild(carName)
	
	if Car then
		local clonedCar = Car:Clone()
		clonedCar.Name = player.Name .. 'sCar'
		clonedCar.Parent = game.Workspace
		clonedCar:MoveTo(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * 15)

	local CarImage = CarImageIds[table.find(CarImageIds,carName)]
		CarSpawnNotificationEvent:FireClient(CarImage)
	end
end)

DeleteCarEvent.OnServerEvent:Connect(function(player, Car)
	if Car then
		Car:Remove()
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
	if Car then
		Car:Remove()
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
		if Car then
			Car:Remove()
		end
	end)
end)

Or you can do this if it makes more sense:

for kId,vName in CarImageIds do
	if vName == carName then
		CarSpawnNotificatonEvent:FireClient(player, kId)
	end
end

Also, pretty sure (added it in) you need to run FireClient() with a player passed in?

with your, i get this error: FireClient: player argument must be a Player object

im getting this error

ServerScriptService.CarSpawner:39: invalid argument #1 to ‘find’ (table expected, got string) - Server - CarSpawner:39

 local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")
local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
local CarSpawnNotificationEvent = ReplicatedStorage:WaitForChild("CarSpawnNotification")

local CarImageIds = {

	["Beige Dune Buggy"] = 6068169587  ,
	["Black Jeep"] = 109662003  ,
	["Black Sedan"] = 242143853 ,
	["Blue SUV"] = 8382532839 ,
	["Ford Shelby Truck"] = 126103845 ,
	["Green camo Jeep"] = 4072026855  ,
	["Lamborghini Aventador SVJ"] = 3142634 ,
	["Pink Jeep"] = 7225067642 ,
	["Police Car"] = 7141615506 ,
	["Red Maserati Car"] = 28261053,
	["Red Sedan"] = 6881212666 ,
	["White Van"] = 7262556994 ,

}







SpawnCarEvent.OnServerEvent:Connect(function(player, carName)
	local Car = ServerStorage:FindFirstChild("Cars"):FindFirstChild(carName)
	
	if Car then
		local clonedCar = Car:Clone()
		clonedCar.Name = player.Name .. 'sCar'
		clonedCar.Parent = game.Workspace
		clonedCar:MoveTo(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * 15)
	
		local CarImage = CarImageIds[table.find(carName,CarImageIds)]
		CarSpawnNotificationEvent:FireClient(CarImage)
			
		
	end
end)

DeleteCarEvent.OnServerEvent:Connect(function(player, Car)
	if Car then
		Car:Remove()
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
	if Car then
		Car:Remove()
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
		if Car then
			Car:Remove()
		end
	end)
end)

Thank you it works.

Capture 2

But then the script that receive the remote event doent change the image labal to the car that was spawned

local script = script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CarSpawnNotificationEvent = ReplicatedStorage:WaitForChild("CarSpawnNotification")






CarSpawnNotificationEvent.OnClientEvent:Connect(function(player, kId)
	CarSpawnNotificationFrame:TweenPosition(UDim2.new(0, 0,0, 0), "InOut", "Quad", 0, true)
	CarSpawnNotificationFrame.Visible = true
	local NotificationImage = script.Parent.ImageSlot.ImageLabel
	NotificationImage = kId
end)

CarSpawnNotificationFrame.MouseButton1Click:Connect(function()
	CarSpawnNotificationFrame:TweenPosition(UDim2.new(-0.13, 0,0, 0), "InOut", "Quad", 1, true)
	wait(1)
	CarSpawnNotificationFrame.Visible = false
end)

You don’t have to strictly name the arguments you send and receive the same thing.
Have you tried using print debugging? It always helps by just printing the variables you want to track through a script. Try printing kId before the :FireClient() event in the for loop.

Im trying toi changer the image to the kId, this is the line of code NotificationImage.Image = kId

but im getting this error: Unable to assign property Image. Content expected, got nil

Again, use print debugging.
Print the variables kId and vName before the event is fired, like this:

for kId,vName in CarImageIds do
	if vName == carName then
		print(kId)
		print(vName)
		CarSpawnNotificatonEvent:FireClient(player, kId)
	end
end

I think you mean:

NotificationImage.ImageId = kId

it does not work, i got this error

ImageId is not a valid member of ImageLabel “Players.dav2777.PlayerGui.MainGUI.CarSpawnNotification.ImageSlot.ImageLabel”

1 Like

Sorry, I meant

NotificationImage.Image = kId

ImageId doesn’t exist, it’s just Image.

1 Like

i changed it to this now its easier but it doesnt change the image