Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error: OnClientEvent is not an valid member of Remote Function "game.ReplicateStorage.HatchEgg"?

So I'm trying to make an egg hatching system that involves a trade between a normal script and a local script. But I'm getting this error and I don't know why:

-- On normal script --

game.ReplicatedStorage.HatchEgg:InvokeClient(player, pet)

-- On local script --

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

I dont know why LUA is treating OnClientEvent like an Instance. Thanks.

1 comment

0

I suggest using something other than InvokeClient, since it can hang forever if it throws an error.

1 answer

✓ Accepted answer

OnClientEvent is only reserved for Remote Events. On Remote Functions You need to use OnClientInvoke

game.ReplicatedStorage.HatchEgg.OnClientInvoke = function(pet)
	return true --You should use remote functions to return stuff.
end)

Also using the player parameter OnClientInvoke is unnecessary. Just put the first parameter as pet otherwise the 2nd parameter would be nil.

3 comments

0

Note: A reason why LUA treats an event like an Instance is because it ALWAYS assumes that you want an instance. There is a hierarchy when you use the dots. So Lua assumes that a (e.g. part) is named OnClientEvent, so it'll search for that.

0

Roblox Lua to be specific

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.