Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When Part is touched the tool gets removed, but doesn't add 10 gold, and doesn't print text? [closed]

Asked by 7 years ago
Edited 7 years ago

The part that works is the part where it gets rid of the item in the backpack on touch but doesn't give gold for it (a sell weapon button). And it also doesn't print the message saying "you bought this for 100" or "you don't have that weapon"

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 = player:WaitForChild('leaderstats').Gold

    if player.Backpack:findFirstChild("Wooden Sword") ~= nil then



    m = Instance.new("Hint")

    m.Text = "You sold your Wooden Sword for 10 gold!" 

    m.Parent = player

    player.Backpack:findFirstChild("Wooden Sword"):remove()
    wait(2)
    gold.Value = gold.Value + 10
    m.Parent = nil

else

    m = Instance.new("Hint")

    m.Text = "You need the Wooden Staff to do this."

    m.Parent = player

    wait(3)

    m.Parent = nil

end



wait(2)

debounce = false

end

end





script.Parent.Touched:connect(onTouch) 

0
The setup is so scary thehybrid576 294 — 7y
0
Wow, this script is an artifact. I'm assuming you didn't write this, @Gamersofthegodss. Pyrondon 2089 — 7y
0
What do you mean? Gamersofthegodss 11 — 7y
0
Soooo many "enter"s. marioblast1244 113 — 7y

Closed as Non-Descriptive by Goulstem

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?