Why isn't the event not firing?

Hey,

I have a problem where I was trying to fire this event to change the camera but it isn’t firing, what is the problem?

Script 1
local cost = 500

local petModule = require(game.ServerScriptService.ModuleScripts:WaitForChild("PetModule"))
local RunService = game:GetService("RunService")
local HatchEgg = game.ReplicatedStorage.Events.HatchEgg
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	print(player.leaderstats.Diamonds.Value)
	if player.leaderstats.Diamonds.Value >= cost then
	    player.leaderstats.Diamonds.Value = player.leaderstats.Diamonds.Value - cost
	    local pet = petModule.chooseRandomPet()
		print(pet.Name.." selected")
		HatchEgg:FireClient(player,pet)
	end
end)
'Event Handler
local camera = game.Workspace.Camera

game.ReplicatedStorage.Events.HatchEgg.OnServerEvent:Connect(function(player,pet)

camera.CameraType = Enum.CameraType.Scriptable

camera.CFrame = game.Workspace.CameraPart.CFrame

print("Hi")

end)

Its not OnServer, its OnClient.

local camera = game.Workspace.Camera

game.ReplicatedStorage.Events.HatchEgg.OnClientEvent:Connect(function(player,pet)

camera.CameraType = Enum.CameraType.Scriptable

camera.CFrame = game.Workspace.CameraPart.CFrame

print("Hi")

end)
1 Like

OnServerEvent is a event that the server receives. OnClientEvent is something a client receives.

1 Like

Still doesn’t work, I have no idea why

1 Like

Try printing before and after the functions run. You are printing a couple lines above or below.

1 Like

I tried debugging this further and I got the same output.

19:56:30.831 0.5, 0.5 - Client
19:56:33.080 1000 - Server - Script:7
19:56:33.080 Bear selected - Server - Script:11
19:57:18.480 Disconnect from ::ffff:127.0.0.1|63659 - Studio
19:57:19.579 Data Has Been Saved - Server - Leaderboard:44

1 Like
game.ReplicatedStorage.Events.HatchEgg.OnClientEvent:Connect(function(pet)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = game.Workspace.CameraPart.CFrame
	print("Hi")
end)

The player argument isn’t received by the callback function connected to the “.OnClientEvent” event only the additional arguments passed to the corresponding “:FireServer()” instance method call are.

Because this is a local script the local player instance can be quickly fetched/referenced via game.Players.LocalPlayer if necessary.

1 Like