Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the remote event not receiving the correct information?

Asked by 6 years ago

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!

0
Are the parameters passed on line 05 in the same order as the parameters received at line 10. Also, does every parameter (on line 05) have a matching parameter to line 10? Nikkasfied 43 — 6y
0
Excluding the 'player' variable on line 05, every parameter matches up with each other from server to client. McRocketNuggets 65 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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. ;)

0
Thank you lazycoolboy500, I really appreciate it! But, what I have just realized is that I named two parameters the same in the client script causing the output to be nil since the last 'topic' parameter is nil. Also, I am using a dictionary so checking whether v == (code) is necessary. McRocketNuggets 65 — 6y
0
That's great! Just so you know that "i,v in pairs" counts the number of children "i" and tells you the name of them "v" which is why I recommended that edit. lazycoolboy500 597 — 6y
0
Also, if you have two variables with the same name you shouldn't get "nil". Roblox kinda bugs out and chooses one of the two. This is the same for calling something in workspace if more than one children have the same name. lazycoolboy500 597 — 6y
Ad

Answer this question