Passing a variable from a local script to a server script through a remote event

Hi, there. I’m making a tool system where I click on a specific item and it’s supposed to give me that item, however I’m running into an issue. The issue is that I’m using a local and a separate server script to pass an argument via remote. However, It seems like the argument isn’t being recognized as I don’t get any tool when I click on it.

Local script:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local prevTarget = nil
local connection 

UIS.InputChanged:Connect(function(input)
	if Mouse.Target then
		if Mouse.Target:FindFirstChild("Pastry") then
			prevTarget = Mouse.Target
			Mouse.Target.Transparency = .95
			Player.PlayerGui.Pastry_Name.Adornee = Mouse.Target
			Player.PlayerGui.Pastry_Name.Enabled = true
			Player.PlayerGui.Pastry_Name.TextLabel.Transparency = 0
			Player.PlayerGui.Pastry_Name.TextLabel.BackgroundTransparency = 1
			Player.PlayerGui.Pastry_Name.TextLabel.Text = Mouse.Target.Name
		elseif prevTarget then
			Mouse.Move:Connect(function()
				prevTarget.Transparency = 1
				Player.PlayerGui.Pastry_Name.Enabled = false
				Player.PlayerGui.Pastry_Name.Adornee = nil
				Player.PlayerGui.Pastry_Name.TextLabel.Text = ""
			end)
			wait()
		end
	end
end)

Mouse.Button1Down:Connect(function()
	if Mouse.Target:FindFirstChild("Pastry") then
	if Player.Backpack:FindFirstChild(Mouse.Target.Name) then
		else
		local DesiredPastry = game.ReplicatedStorage.Pastries:FindFirstChild(Mouse.Target.Name)
		game.ReplicatedFirst.Remotes.UI.ReceivePlayerItem:FireServer(DesiredPastry)
		wait(1)
		end
	end
end)

Server script:

game.ReplicatedFirst.Remotes.UI.ReceivePlayerItem.OnServerEvent:Connect(function(player, DesiredPastry)
	local DesiredPastry_Cloned = DesiredPastry:Clone()
	DesiredPastry_Cloned.Parent = player.Backpack
end)

Any help would be appreciated, thanks.

What errors are being sent? If any

There’s no errors for some reason.

Note: Moving the event to ReplicatedStorage and the server script to ServerScriptService fixed my issue.

1 Like

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