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

Sending a table to the server from a player?

Asked by 6 years ago

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?

0
Do not send the player instance on the local script on line seven. It is sent automatically. RayCurse 1518 — 6y
0
Yeah just say "remoteEvent:FireServer()" if that doesnt fix it then I may have another idea. :) GottaHaveAFunTime 218 — 6y
0
My bad say "remoteEvent:FireServer(data) GottaHaveAFunTime 218 — 6y
0
But then when you have to define who the player is how do you go about it? greybird700 63 — 6y
View all comments (3 more)
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. RayCurse 1518 — 6y
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 greybird700 63 — 6y
0
line 7 needs to be: remoteEvent:FireServer(data) Kulh 125 — 6y

2 answers

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

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)

0
God bless, now I get it Lmao! greybird700 63 — 6y
Ad
Log in to vote
0
Answered by
Kulh 125
6 years ago
Edited 6 years ago

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

Answer this question