Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

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

if data ~= nil then
	--your code stuff
end

1 comment

0

doesn't work, I need the functions to work only when data~=nil

This discussion is preserved as it was. New answers, comments, and votes are closed.