Hello! I am @Enchanted_Tix and I was scripting today in my game that is nearly coming out but I am not very good at parameters and arguments. Especially with events and functions. Unexpectedly, I have a problem that I encountered. The first script (the script that fires the event) is a client script and the script that receives the fired event is a local script. Here’s the client script. I couldn’t get the player:
for i, v in pairs(game.Players:GetChildren()) do
game.ReplicatedStorage.FunctionsEvents.MapSelection:FireAllClients(v, SelectedMap)
end
The player argument is not passed to the OnClientEvent. So the SelectedMap has taken over the plr variable and the selected variable hasn’t been given a value. To get you player you can type game.Players.LocalPlayer because it’s a local script. To find out what’s wrong with your parameters and arguments, you could print them out to see what’s going on.
When you type: game.ReplicatedStorage.FunctionsEvents.MapSelection.OnClientEvent:Connect(function(plr, selected)
The first argument is the selectedmap. You need to get rid of the plr argument and only leave the selected argument. FireAllClients and FireClient doesn’t give you the plr, that’s a characteristic of FireServer only.
Ahh sorry. Since you are firing all clients, no need to loop through, or, you can delete the plr in the second script, because that is not needed. So the first script would look like this:
for i, v in pairs(game.Players:GetChildren()) do
game.ReplicatedStorage.FunctionsEvents.MapSelection:FireClient(v, SelectedMap)
end