Remote Event not returning correctly

local function onLock()
	if selectedTemplate ~= nil then
		print(40)
		local action = not selectedTemplate.Locked.Value
		local result = ReplicatedStorage.Remotes.LockPet:FireServer(player,selectedTemplate.Name,true)
		print(result)
		if result == 2 then
			selectedTemplate.Locked.Value = true
			selectedTemplate:FindFirstChild("Lock").Visible = true
		elseif result == 1 then
			selectedTemplate.Locked.Value = false
			selectedTemplate:FindFirstChild("Lock").Visible = false
		end
	end
end

on the print(result) line it keeps printing nil.
Here is the server side

remotes.LockPet.OnServerEvent:Connect(function(player,tempName,action)
	for i, pet in pairs(player.OtherStats.Pets:GetChildren()) do
		if pet:GetAttribute("UUID") == tempName then
			pet:SetAttribute("Locked",action)
		end
		if pet:GetAttribute("Locked") == false then return 1 else return 2 end
	end
end)

RemoteEvent do not return values, you must use a RemoteFunction.
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

1 Like

Why are you expecting a number for firing LockPet? You aren’t returning anything.

Instead, you should use a Remote Function (like what @SOTR654 mentioned)