Remote Events Not Working?

I have been trying to make a car spawn ui, but the remote event isn’t working
I have a local script in a textbutton in startergui with this code:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.CarSpawnEvent:FireServer(script.Parent.Name)
	print(game.Players.LocalPlayer.Name.." Triggered Car Spawn Event")
end)

I also have a remote event in replicatedstorage called CarSpawnEvent
Lastly i have a server script in server script service with this code:

game.ReplicatedStorage.CarSpawnEvent.OnServerEvent(function(Car)
	local CloneCar = game.ReplicatedStorage.Cars:FindFirstChild(Car)
	if not CloneCar then
		print("Error")
	else
		print("Sucsess")
		CloneCar = CloneCar:Clone()
		CloneCar.Parent = workspace.Cars
	end
	
end)

In the output, i get ‘Bloxer126g triggered car spawn event’ but not ‘sucsess’ or ‘error’

Should be

game.ReplicatedStorage.CarSpawnEvent.OnServerEvent(function(Player, Car)

Because the Player argument is provided automatically as a parameter for OnServerEvent

So you’re actually referencing the player with your current code atm

1 Like

You are not listening to the remote event properly.
CarSpawnEvent.OnServerEvent(function(Car) must be CarSpawnEvent.OnServerEvent:Connect(function(Player, Car).
Also, as @Doomcolp said, first parameter of OnServerEvent is the Player whoever fired the remote.
Although if you listened to the remote properly, it would still not function as intended, since the “Car” is the Player on your current unfixed code.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.