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

How do I make these functions work only when not nil?

Asked by
ItsMeKlc 235 Moderation Voter
8 years ago

I want these functions to work, but only when data has been set. "data" is an object value. The problem is that "data" starts of as nil and these cause my script to break, how can I fix that?

data.Value.Items.ChildAdded:connect(update)
data.Value.Items:WaitForChild(script.Parent.Name).Changed:connect(update)

2 answers

Log in to vote
0
Answered by
ItsMeKlc 235 Moderation Voter
8 years ago

I figured it out, I can just disconnect the old connect before reinstating it. Go me! :)

    if a~= nil then
        a:disconnect()
    end 

    if b~=nil then
        b:disconnect()
    end
    if data.Value~=nil then
        a = data.Value.Items.ChildAdded:connect(update)
        b = data.Value.Items:WaitForChild(script.Parent.Name).Changed:connect(update)
    end
Ad
Log in to vote
-1
Answered by
Kryddan 261 Moderation Voter
8 years ago

I don't think I understood the problem correctly but try this.

if data ~= nil then
    --your code stuff
end
0
doesn't work, I need the functions to work only when data~=nil ItsMeKlc 235 — 8y

Answer this question