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

Keep getting a "attempt to call a nil value" in my output?

Asked by 4 years ago
Edited 4 years ago

I keep getting an "attempt to call a nil value" in my output every time I click on a button, here's my scripts.

local clickDetector = script.Parent.ClickDetector

if script.Parent.Parent.Name == ("Can I get a burrito?") then
    function onMouseClick()
        script.Parent.Parent.Name = ("Thank you!")
    end
end

clickDetector.MouseClick:connect(onMouseClick)

Note that the first script is the same for every name text

while true do
    creativlyNamedVariable = math.random (1, 4)
    if creativlyNamedVariable == 1 then
        script.Parent.Name = ("Can I get a taco?")
    elseif creativlyNamedVariable == 2 then
        script.Parent.Name = ("Can I get some nachos?")
    elseif creativlyNamedVariable == 3 then
        script.Parent.Name = ("Can I get a burrito?")
    elseif creativlyNamedVariable == 4 then
        script.Parent.Name = ("Can I get a soda?")
        if script.Parent.Name == ("Thank you!") then
            wait(30.8)
            creativlyNamedBye = math.random (1, 3)
            if creativlyNamedBye == 1 then
                script.Parent.Name = ("Bye!")
            elseif creativlyNamedBye == 2 then
                script.Parent.Name = ("Cya!")
            elseif creativlyNamedBye == 3 then
                script.Parent.Name =("Alright, have a good one!")
            end
        end
    end
    wait(35.8)
end 

EDIT: So I just tested it again. But it works with some buttons one time, and then others when I test it another time.

0
what line? Leamir 3138 — 4y
0
No idea, just sometimes when I click on the button it will say "attempt to call a nil value". Don't know why at all. I did try to add variables, but that didn't help. sadly :( harrylary -5 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Well I found it out

local clickDetector = script.Parent.ClickDetector

function onMouseClick()
    if script.Parent.Parent.Name == ("Can I get a burrito?") then
        script.Parent.Parent.Name = ("Thank you!")
    end
end

clickDetector.MouseClick:connect(onMouseClick)

Just needed to put line 3 into the function. Now it works every time!

Ad

Answer this question