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?
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:
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)
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