So I'm working on something but it's not working. I'm trying to sell a "tool" thats in the starter pack. Here is the script:
local debounce = false
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false then
debounce = true
local player = getPlayer(human)
if (player == nil) then return end
user = game.Players:findFirstChild(human.Parent.Name)
local gold = user.leaderstats.Gold
if player.StarterGear:findFirstChild(script.Parent.Parent.SETTINGS.Item.Value) ~= nil 18. then
gold.Value = gold.Value + script.Parent.Parent.SETTINGS.SellbackPrice.Value
m = Instance.new("Hint")
m.Text = "You sold " ..script.Parent.Parent.SETTINGS.Item.Value.. " for " 22. ..script.Parent.Parent.SETTINGS.SellbackPrice.Value.. " gold!" -- message
m.Parent = player.PlayerGui
player.Backpack:findFirstChild(script.Parent.Parent.SETTINGS.Item.Value):remove()
player.StarterGear:findFirstChild(script.Parent.Parent.SETTINGS.Item.Value):remove()
wait(2)
m.Parent = nil
else
m = Instance.new("Hint")
m.Text = "You need the " ..script.Parent.Parent.SETTINGS.Item.Value.. " to do this."
m.Parent = player.PlayerGui
wait(3)
m.Parent = nil
end
wait(2)
debounce = false
end
end
script.Parent.Touched:connect(onTouch)
I already have the SETTINGS and let's say the object I'm trying sell is called "Apple".
FYI this is not for a Gamepass or a DEV Product!!! Iy may also be notable that you get the item from a "giver".