Why is my remote event getting nil?

What did I do wrong here?

I am trying to make an npc where you can sell tools for gold but the remote event thinks the information i gave it is different or nil

server script

local event = repsotrage:WaitForChild("ShopRE")

idleanim:Play()


script.Parent.ClickDetector.MouseClick:Connect(function(player)
	event:FireClient(player)
end)

event.OnServerEvent:Connect(function(player, goldtoadd, tool, toolname)
	print(goldtoadd) --this prints as the player
	print(tool) --this prints as nil
	print(toolname) --thisprints as nil
	player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + goldtoadd
	tool:Destroy()
	player.StarterGear:FindFirstChild(toolname):Destroy()
end)

local script

local dialogue = script.Parent:WaitForChild("Dialogue")
local Yoption = dialogue:WaitForChild("Accept")
local Noption = dialogue:WaitForChild("Decline")
local speech = dialogue:WaitForChild("Speech")
local textvalue = 1
local repsotrage = game.ReplicatedStorage
local event = repsotrage:WaitForChild("ShopRE")
local player = game.Players.LocalPlayer

speech.Text = "Hod the item you wish to sell"
Noption.Text = "Bye"
Yoption.Text = "I want to sell this"

local function sellitem()
	local toolvalue
	local tool
	local toolname
	if textvalue == 1 then
		speech.Text = "Hold the item you wish to sell"
		Yoption.Text = "I want to sell this"
		textvalue = 2
	else if textvalue == 2 then
			tool = player.Character:FindFirstChildOfClass("Tool")
			if tool ~= nil then
				itemrarity = tool.Price.Value
				tname = tool.Name
				speech.Text = "I will buy that " ..toolname.. " for " ..toolvalue.. " Gold"
				Yoption.Text = "Sure"
				textvalue = 3
			end
		else if textvalue == 3 then
				event:FireServer(player, toolvalue, tool, tname)
				speech.Text = "Hold the item you wish to sell"
				Yoption.Text = "I want to sell this"
				textvalue = 1
				Dialogue.Visible = false
			end
		end
	end
end

Yoption.MouseButton1Click:Connect(function()
	sellitem()
end)

Noption.MouseButton1Click:Connect(function()
	dialogue.Visible = false
	speech.Text = "Hold the item you wish to sell"
	Yoption.Text = "I want to sell this"
	textvalue = 1
end)
	
event.OnClientEvent:Connect(function()
	dialogue.Visible = true
end)



Ok. I’m not too sure but could you try to remove the player argument from the local script when your firing the event and tell what do you get

Also could you just also add the print statements in the local script just to make sure that the values are actaully there in the local side

1 Like

the variables in the local script become nil only when this fires

else if textvalue == 3 then
				event:FireServer(player, toolvalue, tool, toolname)
				speech.Text = "Hold the item you wish to sell"
				Yoption.Text = "I want to sell this"
				textvalue = 1
				Dialogue.Visible = false
			end

I didn’t quite understand… I think you meant that when the textValue is 2 or 1 then the values are present. But when it becomes 3, then the values go?
Am I right?
And also where have you assigned the tool, toolValue and toolName in the localSide?

Edit: I’m not too sure, but I think the problem is that every time the function runs, it creates new variables, so try to make the variables tool, toolValue and toolName outside the function and remove the local variables from the function.(at the start)

1 Like

:FireServer passes the player implicitly. You don’t need to give it as the first argument.

Change
event:FireServer(player, toolvalue, tool, tname)
to
event:FireServer(toolvalue, tool, tname)

1 Like