Client receives pet model from server nil

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to make a pet hatch animation with a viewport frame (so egg model and pet model) and this animation happens after a remote event from the server is fired. The parameters are 6 (because of another script that uses the same remote event)
  2. What is the issue? Include screenshots / videos if possible!
    The issues is that whenever the pet is suppose to show up, an error is caused, which basically im indexing a nil value. I tried debugging and figured out that whenever the client receives the pet model, it receives a nil value, tho i dont understand how as i have an eggmodel passed from the server which works fine (maybe because i sent the eggmodel to the server then have it back to the client).
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried to look issues like this and there are, but the issues i find have always the same answer: “The client cannot acces the server storage”, though the pet models are in replicated storage.

This is the server side code:

local function Hatch(player, eggId, amount, eggModel)
	if HatchCooldown[player.UserId] then return end
	
	local eggConfig = EggConfig[eggId]
	local playerBalance = player.leaderstats.Money.Value
	if playerBalance < eggConfig.Price then return end

	HatchCooldown[player.UserId] = true
	player.leaderstats.Money.Value -= eggConfig.Price
	
	local chosenPet = ChoosePet(eggConfig.Pets)	
	local petModel = petModels[chosenPet.ID]:Clone()
	local petInstance = Rewards.Pet(player, chosenPet.ID, chosenPet.Rarity, amount)
	print(petModel)
	PetHatched:FireClient(player, chosenPet,  petInstance, eggId, eggModel, petModel)
	
	task.delay(HATCH_COOLDOWN, function()
		HatchCooldown[player.UserId] = nil
	end)
end

the client side:

PetHatched.OnClientEvent:Connect(function(pet, amount, petInstance, eggId, eggModel, petModel)
	print(petModel)
	
	viewportHatch.Size = UDim2.fromScale(0, 0)
	local eggModel = eggModel:Clone()
	eggModel.Parent = viewportHatch
	eggModel.CFrame = CFrame.new(0, 0, 0)
	
	print(petModel) --receives nil
	petModel:PivotTo(CFrame.new(0, 0, 0))--the error
	petModel.Parent = viewportHatch
	
	--this isnt the full code, i just made it shorter
end)

Can you check if it prints the petmodel in the server side?

So i actually found out that cloning in the server results a nil when passing it to the client (probably because then the parent is nil when you clone), and yes the pet model did print out from the server. Though now i have a new error "The Parent property of Camera is locked, current parent: NULL, new parent ViewportFrame ", but ill try to look into it

What is amount suppose to be?
image

For some reason i removed it from the codeblock, but that isnt the issue (though its an intvalue). and about the error i got after fixxing the original error, i already fixxed that but am facing another issue where the petmodel doesnt show up.

Ok i actually setup the camera wrong, so now its fixxed.

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