Does anyone know how I can communicate a special variable from a local script to a server script using remote event?

Local Script:

local sendrequest = game.ReplicatedStorage:WaitForChild("GiveItem").SendRequest
local sendback = game.ReplicatedStorage:WaitForChild("GiveItem").Sendback
local frameTemplate = game.ReplicatedStorage:WaitForChild("GiveItem").Frame

local player = game.Players.LocalPlayer

sendrequest.OnClientEvent:Connect(function(target, playername, itemname)
	if target.Name == player.Name then
		local frame = frameTemplate:Clone()
		frame.Parent = script.Parent.Frame

		frame.TextLabel.Text = playername.." would like to give you a "..itemname

		frame.Yes.MouseButton1Click:Connect(function()
			frame:Destroy()
			sendback:FireServer(itemname)
		end)

		frame.No.MouseButton1Click:Connect(function()
			frame:Destroy()
		end)
	end
end)

Server Script:

local sendback = game.ReplicatedStorage:WaitForChild("GiveItem").Sendback

sendback.OnServerEvent:Connect(function(item)
	print(item)
end)

As of right now, it just prints the player’s name. I want it to print the itemname.

1 Like

When you use a remote event, the first parameter passed through is always the player, and then whatever you passed yourself after that.

So to get the item you can do this.

local sendback = game.ReplicatedStorage:WaitForChild(“GiveItem”).Sendback

sendback.OnServerEvent:Connect(function(player, item)
print(item)
end)

(Sorry for not formatting code, I’m on mobile.)

3 Likes

oohhhhh, tysm. taught me something new

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.