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)