Remote Functions Help

Hey fellow programmers!

I need some help with remote functions as I’m dumb and yeah…
So I have a remote function and it just doesn’t work.

Local script

script.Parent.MouseButton1Click:Connect(function()
	
	local chosenPet = EggOpener:InvokeServer(value)
	
	print(chosenPet)
end)

Server Script

EggOpener.OnServerInvoke = function(player, value)
	
	local EggSelected = petRoll.Roll(value)
	local chosenPet = petModule.chooseRandomPet(EggSelected)
	
	return chosenPet
end

(It’s supposed to print out the pet, but it doesn’t print anything, the Module scripts work indeed)

Any idea? Thanks in advance!

More explanation in the comments!

We would probably need to see more of the script to see what’s going wrong, but step 1 is to check output for any errors, and then make sure your modules aren’t breaking or doing something wrong.

Also keep in mind if something is stopping the .OnServerInvoke from running such as a while true do loop.

In local script when you invokeServer. What is the value argument?

The module scripts work completely fine, the 1st one is to determine if it’s using like a first egg or 2nd egg, and the 2nd module is to determine the pet from that specific egg, it works tho but it doesn’t print out the chosenPet (even if i do chosenPet.Name)

So the value determines which egg he’s gonna open, example if i stand on the first egg, the value is one, and in the module script if it’s 1 then it will get a random pet from the Egg number 1

Do you get an error in the devconsole?
If yes… can you show the error?

Are you sure that there is no problem with module script?

No errors in the console at all…

The module scripts work with no problem i already tested them

The module script is supposed to give you a random pet ( as an object not string or anything)

Try keep printing stuff between everything, and try to find what is the problem from.

script.Parent.MouseButton1Click:Connect(function()
   print("The Button Click Works")
   local chosenPet = EggOpener:InvokeServer(value)
end
EggOpener.OnServerInvoke = function(player, value)
print("The Invoke works!")
	local EggSelected = petRoll.Roll(value)
	print("The Egg has been selected!")
	local chosenPet = petModule.chooseRandomPet(EggSelected)
	print("The pet has been chosen!")

It only printed out “The button works!”

Ok, there is something wrong with the remote function on the server script. Try to replace that
EggOpener.OnServerInvoke
with the place of the remote function.

Also in local script
EggOpener:InvokeServer(Value)

 The Button Click Works
  The Invoke works!
  The Egg has been selected!
  The pet has been chosen!
  Pet has been chosen!
  nil

The pet printed out nil

Try to print chosenPet if it give you nil that mean from module if it doesn’t then.
Add in the script before return
repeat wait() until chosenPet

Its reference will be nil on the server if “value” doesn’t exist on the server, it has to exist both on the server and client.

What is value anyways?

I asked that thing, she didn’t include it in the script.

The value is 1 it indicated that it should open the Egg1 so it chooses specific pets for that egg

Code please.

1 Like