Remote event issue

hello, im currently a car spawning system ( A gui with cars you can spawn). When you spawn a car there is a gui that pops up on your screen saying you spawned a car. in that gui, i went too add a image that changes according to the car you spawned.

This is the gui that pops up:
gui

This is the car spawning gui, i want to the image in the pop up correspond to the car you spawn.
cars

Here is the problem im getting this error: Unable to cast value to Object.
These are the scripts:

#1 This is the script that’s in the buttons of the previous image.

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local SpawnCarEvent = ReplicatedStorage:WaitForChild(“SpawnCar”)
local DeleteCarEvent = ReplicatedStorage:WaitForChild(“DeleteCar”)
local carName = script.Parent.Name
local SpawnCarFrame = script.Parent.Parent.Parent.Parent.Parent.CarSpawnFrame
local CarImage = script.Parent.Image

script.Parent.MouseButton1Down:Connect(function()
SpawnCarFrame.Visible = false
SpawnCarFrame:TweenPosition(UDim2.new(0.5, -250,1.16, -200), Enum.EasingDirection.In, Enum.EasingStyle.Quad)
local CurrentCar = game.Workspace:FindFirstChild(player.Name … ‘sCar’)
if not CurrentCar then
SpawnCarEvent:FireServer(carName, CarImage)
else
if player.Character.Humanoid.SeatPart ~= nil and player.Character.Humanoid.SeatPart:IsA(“VehicleSeat”) then
player.Character.Humanoid.Sit = false
end
wait()
DeleteCarEvent:FireServer(CurrentCar)
SpawnCarEvent:FireServer(carName, CarImage)
end
end)



#2 This is the script in ServerScriptService, this is the script that receive the spawn caar remove event and also triggers the remote event, to make the gui pop up when the car is spawned.

``` 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”)

SpawnCarEvent.OnServerEvent:Connect(function(player, carName, CarImage)
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)
	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)


#3 this is the script for the pop up gui.

local CarSpawnNotificationFrame = script.Parent.Parent.CarSpawnNotification
local script = script
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local CarSpawnNotificationEvent = ReplicatedStorage:WaitForChild(“CarSpawnNotification”)

CarSpawnNotificationEvent.OnClientEvent:Connect(function(carName)
CarSpawnNotificationFrame:TweenPosition(UDim2.new(0, 0,0, 0), “InOut”, “Quad”, 0, true)
CarSpawnNotificationFrame.Visible = true
local NotificationImage = script.Parent.ImageSlot.ImageLabel
NotificationImage.Image = carName

end)

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



The error im getting is because of the CarImage in put in the first script, i put that so the script is going to know what image is going to be in the pop up gui. But for some reason it doesnt work.




If you could help and know a fix to this, I would appreciate it. :smile: 

Thank you

sorry, the rest of the information was put in the script zone

What part of your script isn’t working? Have you tried debugging it with Print() or breakpoints?

Wouldn’t it be less complex to just store the images in ReplicatedStorage rather than the server? You have all these remote events that can be heavily exploited if you’re not careful.

Can you tell us what line the error is on? Also, it’s potentially because CarImage is an image Instance, which is an object. You can’t transfer object instances over remote events because thats quite unsafe. It’s better if you do CarImage.ImageId as this still retains the info of which image it is.