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

Can you overload functions?

If i have two functions with the same name but different parameters taken that get called OnServerEvent, will this work?

game.ReplicatedStorage.addToFishCountEvent.OnServerEvent:Connect(function(player, fishName)
	
end)

game.ReplicatedStorage.addToFishCountEvent.OnServerEvent:Connect(function(player, fishName, Quantity)
	--this one has Quantity as a parameter
end)

Can you overload like this?

Thank you for any help.

3 comments

0

You can use while loops, they are loops that repeat over and over.

0

lol

1

No. You can't overload functions in Lua. Instead, people often use ternary operators to correct wrongly assigned parameters.

1 answer

I recommend using different RemoteEvents (assuming you are using them), by just naming them differently they will work the same but without messing anything up. (The server events cna be connected to the same thing, just do the FireServer() twice but defining the different RemoteEvent names. (Unless you're trying to overload them, that is!)

game.ReplicatedStorage.addToFishCountFirstEvent.OnServerEvent:connect(function(player)

end)

game.ReplicatedStorage.addToFishCountSecondEvent.OnServerEvent:connect(function(player)

end)

2 comments

0

So can you not overload?

0

I'm not sure, but it's best to do this (if you don't want to overload) as a back up to ensure nothing goes wrong.

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