My RemoteEvent is not working

Hello, Recently I have been having a problem with remote events. I am trying to help my friend by fixing his egg hatching system. While doing that I noticed that a vital RemoteEvent is not sending anything to the player (tested with print statements).

I have tried looking for naming errors already. There are no errors in output either.

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!

Server Code:

local cost = 250
local PetModule = require(game.ServerScriptService:WaitForChild("PetModule"))

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if player.leaderstats.Cash.Value >= cost then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
		local pet = PetModule.chooseRandomPet()
		print(pet.name.." selected")
		local name = player.Name
		
		game.ReplicatedStorage.HatchEgg:FireClient(player, pet) --Remote is not sending the anything for some reason
		
	end
end)

Client Code: (Variables are above the shown function)

    game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
    	camera.CameraType = Enum.CameraType.Scriptable
    	camera.CFrame = studio.Campart.CFrame
    	print("TEST")
    end)

I hope someone can help me with finding the reason behind this error.

Can I ask what type of data this function returns? Instance, table or what?

It gets something random out of a table with all the possible pets and then it returns that.

Perhaps the Client Code isn’t able to find the RemoteEvent, thus you should add a WaitForChild event that waits for the RemoteEvent to load into the ReplicatedStorage. I’m not a good scripter myself, but I would still want to give out all the help I can give. Try this adding this at the start of your ClientScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HatchEgg = ReplicatedStorage:WaitForChild("HatchEgg")

I have tried your solution but it does not work. The output says that there is nothing wrong.

This is going to sound kinda obvious, but the remote event wouldn’t send unless you have enough cash to buy the pet. Can your perhaps provide your module so we can better help?

Here is the whole PetModule:

local petModule = {}

petModule.pets = {

	["Legendary"] = {
		game.ReplicatedStorage.Pets.Umbreon;
		game.ReplicatedStorage.Pets.Marill;
	};

	["Rare"] = {

		game.ReplicatedStorage.Pets.Snorlax;
	};

	["Uncommon"] = {

		game.ReplicatedStorage.Pets.Pikachu;
		game.ReplicatedStorage.Pets.Bulbasaur;
		game.ReplicatedStorage.Pets.Charmander;
		game.ReplicatedStorage.Pets.Squirtle;


	};

	["Common"] = {
		game.ReplicatedStorage.Pets.Eevee;


	};

}

petModule.rarities = {

	["Legendary"] = 4;

	["Rare"] = 15;

	["Uncommon"] = 35;

	["Common"] = 50;

}

petModule.chooseRandomPet = function ()

	local randomNumber = math.random(1,100)

	local counter = 5

	for rarity, weight in pairs(petModule.rarities) do
		counter = counter + weight
		if randomNumber <= counter then

			local rarityTable = petModule.pets[rarity]
			local chosePet = rarityTable[math.random(1,#rarityTable)]

			return chosePet

		end
	end


end

return petModule

Are there any loops or waits above the OnClientEvent event? Because if that’s the case then just wrap the loop/wait in a coroutine and you should be good.

No, There are no loops above the OnClientEvent Event.

So just a question does

print(pet.name.." selected")

print?

Yes, This print works perfectly fine.

So it only does not print("Test") right?

No, it does not. No errors either.

Maybe try having another client script to test the remote event. Just only put a print in side and tell us if it prints

Is there any code above the Client function?
Like another event, loop, etc

No there are only variables above the client function.

Where is it located in the explorer?
I’m guessing a Gui but I need confirmation

I tested it and the new localscript worked.

The newly created LocalScript:

game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
	print("TEST A")
end)

That means it might be a problem in the petmodule

Well that was my first guess but the “print” statement on the server is printing if there is a error in the module it would stop the thread