Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Where is problem in this script, Sell GUI in RPG?

Hello, I have question where is problem/error in this script? It should sell certain item from starterpack, but it always says "You don't have...", when i hold it in backpack. I tried some changes, but didn't work. It's not my script, my friend made it.

Here is script:

local tabs = script.Parent.TABS:GetChildren()
for i = 1, #tabs do
local buttons = tabs[i]:GetChildren()
for i = 1, #buttons do
function sell()
local hint = Instance.new("Hint",script.Parent.Parent.Parent.Parent.PlayerGui)
local gp = script.Parent.Parent.Parent.Parent.leaderstats:FindFirstChild("Gold")
local bp = script.Parent.Parent.Parent.Parent.Backpack
local sg = script.Parent.Parent.Parent.Parent.StarterGear
local bptool = bp:FindFirstChild(buttons[i].Item.Value)
local sgtool = sg:FindFirstChild(buttons[i].Item.Value)
local sellvalue = buttons[i].SellPrice.Value
if bptool ~= nil and sgtool ~= nil then
bptool:Remove()
sgtool:Remove()
gp.Value = gp.Value + sellvalue
hint.Text = "You sold " ..buttons[i].Text.. " for " ..buttons[i].PriceDisplay.Text.. " Gold!"
elseif bptool == nil and sgtool ~= nil then
sgtool:Remove()
gp.Value = gp.Value + sellvalue
hint.Text = "You sold " ..buttons[i].Text.. " for " ..buttons[i].PriceDisplay.Text.. " Gold!"
else hint.Text = "You don't have " ..buttons[i].Text.. "!"
end
local cl = script.Clean:Clone()
cl.Parent = hint
cl.Disabled = false
end
buttons[i].MouseButton1Click:connect(sell)
end
end

1 comment

0

This code checks for tools you have in the users' backpack, if the user is holding it in their hand it won't work. Plus, if the user picked up the tool off the ground, the code won't work because it checks for the Startergear as well

1 answer

if bptool ~= nil and sgtool ~= nil then | else hint.Text = "You don't have " ..buttons[i].Text.. "!" These are two important parts in the script that need changing.

Currently, you have it set up, so that when you have the tool, and tool has this value, then it says You don't have ___!


if bptool ~= nil and sgtool ~= nil then
bptool:Remove()
sgtool:Remove()
gp.Value = gp.Value + sellvalue
hint.Text = "You sold " ..buttons[i].Text.. " for " ..buttons[i].PriceDisplay.Text.. " Gold!"
elseif bptool == nil and sgtool ~= nil then
sgtool:Remove()
gp.Value = gp.Value + sellvalue
hint.Text = "You sold " ..buttons[i].Text.. " for " ..buttons[i].PriceDisplay.Text.. " Gold!"
else hint.Text = "You don't have " ..buttons[i].Text.. "!"
end

That's what I see from taking a quick glance at it.

1 comment

0

Mhm, but how to fix it? I'm still novice in scripting.

This discussion is preserved as it was. New answers, comments, and votes are closed.