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

Sending a table to the server from a player?

I'm new to tables but what I want to do is send a stringvalue to from a player to the server. local script:


local player = game.Players.LocalPlayer
script.Parent.MouseButton2Click:connect(function()
local ItemDropping = script.Parent.Parent.Item.Value
local remoteEvent = game.ReplicatedStorage.NameOfDroppingItem
local data = {}
data[1] = ""..ItemDropping..""
remoteEvent:FireServer(player, data)

	
end)


server script:

local event = game.ReplicatedStorage:WaitForChild("NameOfDroppingItem")

local function onCreatePartFired(player, data)


do

print ("THIS IS YOUR NAME" .. player.Name)
player.Character.ItemDropping.Value = data[1]




end
end
event.OnServerEvent:Connect(onCreatePartFired)

Can anybody help/ or fix this?

7 comments

0

Do not send the player instance on the local script on line seven. It is sent automatically.

0

Yeah just say "remoteEvent:FireServer()" if that doesnt fix it then I may have another idea. :)

0

My bad say "remoteEvent:FireServer(data)

0

But then when you have to define who the player is how do you go about it?

0

As said previously, the player is sent automatically through the remote event. The player would be the first argument received from OnServerEvent so you do not have to change anything in the server script.

0

If it is sent automatically how am I supposed to define it when I talk about it? It says attempt to index global 'player' (a nil value) if I remove it

0

line 7 needs to be: remoteEvent:FireServer(data)

2 answers

✓ Accepted answer

The player instance is sent automatically through the remote event when fired from a client. This means that you, the scripter, do not have to explicitly put the player argument when you call FireServer in the local script. Keep in mind that this would change absolutely nothing on the server script.

Local Script:

local player = game.Players.LocalPlayer
script.Parent.MouseButton2Click:Connect(function()
	local ItemDropping = script.Parent.Parent.Item.Value
	local remoteEvent = game.ReplicatedStorage.NameOfDroppingItem
	local data = {}
	data[1] = ""..ItemDropping..""

	remoteEvent:FireServer(data)
end)

Server Script:

(Nothing changes here)
local event = game.ReplicatedStorage:WaitForChild("NameOfDroppingItem")
local function onCreatePartFired(player, data)
	do
		print ("THIS IS YOUR NAME" .. player.Name)
		player.Character.ItemDropping.Value = data[1]
	end
end
event.OnServerEvent:Connect(onCreatePartFired)

1 comment

0

God bless, now I get it Lmao!

Line 7 on the local script needs to be:

remoteEvent:FireServer(data)

then the Server Script needs to be:

game.ReplicatedStorage:WaitForChild"NameOfDroppingItem".OnServerEvent:Connect(function(player,data)

print ("THIS IS YOUR NAME" .. player.Name)
player.Character.ItemDropping.Value = data[1]

end)

Make sure you have the server script located in ServerScriptService

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