Answered by
6 years ago Edited 6 years ago
Haha I see this often, people calling the function when they were supposed to pass it in! Don't worry I only know this because I made the same mistake before...
The Confusion
Functions can be passed in as arguments into other functions along with values (sorry, the way I worded it is more confusing than what it actually is), a cheap example:
01 | local function myFunc(f, x) |
07 | print ( "Function (f) was called with argument (" .. x .. ")!" ) |
"Hey, that seems pretty useless."
Sure, in this scenario it looks and probably is very useless.
An easy example would be events, which you are already using so lets go with it.
Snippet of your code:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local donateEvent = Instance.new( "RemoteEvent" , ReplicatedStorage) |
03 | donateEvent.Name = "DonateEvent" |
05 | function checkDonation(player, donationUser, donationAmount) |
07 | game.Workspace.DonationUser.Value = donationUser |
08 | game.Workspace.DonationUser.DonationAmount.Value = donationAmount |
11 | donateEvent.OnServerEvent:Connect( checkDonation() ) |
Here to Connect(...)
the OnServerEvent event a function is needed, you might have thought you passed in a function but you actually called the function and passed in whatever it returned which was nil
.
2 | return x ^ 2 + 2 * x + 1 |
Look at the difference when you call a function with parentheses and when you don't? Well now you know.
So the event never fired the function, but it was instead called with no arguments, the same thing as passing in nil for every argument. Now you know what's causing the problem, and now for the part everyone was waiting for...
Solution
TL;DR Just remove the parentheses next to checkDonation
below, ¯\_(insert japanese word here)_/¯.
There's a good chance I made a mistake or have it all completely wrong, just reply with a comment so I can figure out the real problem.