Parameters and Argument trouble: RemoteEvents

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

and the local script:

game.ReplicatedStorage.FunctionsEvents.MapSelection.OnClientEvent:Connect(function(plr, selected)
	script.Parent.MapFrame.Visible = true
	script.Parent.MapFrame.TitleOfMap.Text = selected.MapSettings.MapName.Value
	script.Parent.MapFrame.Difficulty.Text = selected.MapSettings.Difficulty.Value
	script.Parent.MapFrame.Difficulty.TextColor3 = Color3.fromHSV(game.ReplicatedStorage.ColorFolderTags:FindFirstChild(selected.MapSettings.Difficulty.Value))
	script.Parent.MapFrame.MapPerson.Text = selected.MapSettings.Owner.Value
	wait(4)
	script.Parent.MapFrame.Visible = false
end)

Again, if it was easy, just tell me. Please respond.

OnClientEvent doesn’t require the Player argument. The localscript already knows who the client is.

1 Like

You don’t need to pass in a player parameter for the fireallclients function because it’s firing for all the clients.

You should type:
game.ReplicatedStorage.FunctionsEvents.MapSelection:FireAllClients(SelectedMap)

18:54:44.776 - Players.Enchanted_Tix.PlayerGui.Core.ShopScript:115: attempt to index local 'selected' (a nil value)

I did but it did not work.

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.

I know that but I am saying what is the problem with the ‘selected’ variable being empty or hasn’t been given a value.

Also I given it a value.

local SelectedMap = Maps[math.random(1, #Maps)]

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.

You don’t know what I am saying, @iNoobe_yt

For the first script, just delete the v in the first parameter

People who kept saying that, I already did that but there is still an error.

Enchanted, please re-read what I wrote.

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

and the local script would look like this:

game.ReplicatedStorage.FunctionsEvents.MapSelection.OnClientEvent:Connect(function(selected)
	script.Parent.MapFrame.Visible = true
	script.Parent.MapFrame.TitleOfMap.Text = selected.MapSettings.MapName.Value
	script.Parent.MapFrame.Difficulty.Text = selected.MapSettings.Difficulty.Value
	script.Parent.MapFrame.Difficulty.TextColor3 = Color3.fromHSV(game.ReplicatedStorage.ColorFolderTags:FindFirstChild(selected.MapSettings.Difficulty.Value))
	script.Parent.MapFrame.MapPerson.Text = selected.MapSettings.Owner.Value
	wait(4)
	script.Parent.MapFrame.Visible = false
end)

notice how I deleted the first parameter in the local script

1 Like