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

What is wrong with my script?

Asked by 9 years ago

EDIT : The main problem is that the cash.Value (local cash = stats:findFirstChild("Candy") --Get money) gives nil value. The problem with this is that I do have a leaderstat with the Candy as the currency.

What happens is my script passes by the print("Cat") and print("Dog") commands but then it does not pass print("Mow"). I do believe it has something to do with the cash value, correct me if i'm wrong. I have no errors when this happens. Any help?

local ting = 0 --debouncer

function onClick(mouse)
print("Hi")
    if ting == 0 then --debounce check
    ting = 1 --activate debounce
    check = mouse.Parent:FindFirstChild("Humanoid") --Find the human that touched the button
    print("Hillo")

    if check == nil then --If a human is found, then
        print("Hullo")

        local user = game.Players:GetPlayerFromCharacter(mouse.Parent) --get player from touching human
        print("Here")
        local stats = game.Workspace:findFirstChild("leaderstats") --Find moneyholder
        print("Hello")

        if stats ~= nil then --If moneyholder exists then
            print("Cat")
            local cash = stats:findFirstChild("Candy") --Get money
            print("Dog")
            cash.Value  = cash.Value + 3
            print("Mow")
            wait(0.3) --wait-time before button works again
            print("Wof")
        end

    end

    ting = 0 --remove debounce
    end

end

script.Parent.ClickDetector.MouseClick:connect(onClick)

Thanks.

0
There has to be an output error for this script. funyun 958 — 9y
0
08:01:03.190 - Workspace.Halloween kit.Clickswitch.Script:27: attempt to index local 'cash' (a nil value). It turns out I do have errors, they were just hiding with some of the dialog I told the script to do. Skepticlemon 24 — 9y
0
Can you post your entire script, the code you provided is not enough for us to help you. Bman8765 270 — 9y
0
Edit your question funyun 958 — 9y
View all comments (2 more)
0
There. Skepticlemon 24 — 9y
0
So, does anybody know how to fix this? Skepticlemon 24 — 9y

Answer this question