I constructed an event that fires to the client and checks whether or not the client entered a correct code. When the server fires the event with specific parameters, the client doesn't receive the parameters and returns it as 'nil'. I don't know why the client is not receiving these parameters as I have never encountered it in the past. Here's some of the code.
--Server-- for i,v in pairs(TwitterCodes) do if i == tostring(code) then print(player.Name.." redeemed code: "..code) CodeEvent:FireClient(player,"Accepted",v.Description,v.Cash,v.Reward,v.RewardDecrease,v.RewardTopic,v.RewardImage) break end end --Client-- function CodeOutcome(topic,text,cash,reward,decrease,topic,image) print(topic) -- returns as nil if topic == "Accepted" then TransferCash(cash) playerGui.TwitterFrame.Outcome.Text = tostring(text) if reward ~= nil then TwitterRewardTransfer(reward,decrease,topic,image) end wait(3) playerGui.TwitterFrame.Outcome.Text = "" end end CodeEvent.OnClientEvent:Connect(CodeOutcome)
There are no errors in the output when the event is called, so I am completely CLUELESS on what's going on. Thank you!
Unless you're intending to check if the code is the same number of codes your game has, I would recommend switching that if statement.
Your fixed "if" statement on the server side:
for i,v in pairs(TwitterCodes) do if v == tostring(code) then --"v" stands for variable and "i" stands for intiger (which is why "i,v in pairs" is so popular) CodeEvent:FireClient(player,"Accepted",v.Description,v.Cash,v.Reward,v.RewardDecrease,v.RewardTopic,v.RewardImage) --Your original event break end end
For the client side, I assume that that print function returns as "nil" because it has no set value yet. It's very likely because you called it at the end of the function so it changes AFTER it's printed.
Here's a small fix that I did to it:
CodeEvent.OnClientEvent:Connect(function(topic,text,cash,reward,decrease,topic,image) --Does the exact same thing but cleaner --Your other code print(topic) --Now that it's called after the function, you shouldn't get "nil" in your output end)
If you have any questions or problems please contact me. ;)