Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

script receiving Arguments and parameters wrong using remote events. Help?

I got this following local script:

script.Parent.MouseButton1Click:connect(function()
	local ThePlayerName = script.Parent.Parent:WaitForChild("PlayerNameHere").Text
	script.Parent.Parent.Parent.Parent:WaitForChild("TotalBans").Main.UnBanPlayer:FireServer(ThePlayerName)
	print(ThePlayerName.."'s the player name that got sent!")
end)

And other following one:

script:WaitForChild("UnBanPlayer").OnServerEvent:connect(function(PlayerName)
	local points = 0
	for i,t in pairs (BannedPeople) do
		points = points + 1
		if t == (PlayerName) then
			table.remove(BannedPeople,points)
			print(PlayerName.." successfully removed!")
		end
	end
	points = 0
	---------
	advance = 0
	print(PlayerName.." Is the player name received!")

I keep getting this error: 15:52:49.478 - Players.wilsonsilva007.PlayerGui.AdminGui.Background.TotalBans.Main:37: attempt to concatenate local 'PlayerName' (a userdata value)

But when I changed the PlayerName to PlayerName.Name it just printed my username..

I just want the script to send a 'Name' and receive that 'Name'. Only that. And this is getting me annoyed..

With 'OnClientEvent' and 'FireClient' it worked well in studio but didn't work in game.. And I'm unsure what I'm doing wrong.

Help would be apreciated! Thank you very much for your attention!

P.S. I didn't pay much attention to Arguments and parameters so if this is a really stupid and dumb question I'm sorry. /:

1 answer

✓ Accepted answer

The first parameter of the OnServerEvent event is the player who fired it. All other arguments go after.

RemoteEvent.OnServerEvent:Connect(function(player,PlayerName)
	-- player is the player that called the event.
	-- PlayerName is the argument that you put when you called it.
end

Whenever you use OnServerEvent on OnServerInvoke, add player as the first argument.

1 comment

0

Fixed, and thanks for being so fast!

This discussion is preserved as it was. New answers, comments, and votes are closed.