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

How to make my script keep checking if a string exists, and if it doesnt, create a string?

Works now :) (Posted as a comment)

When a decal is inside the part, I want this script to check if the part has a value inside it.

If not, create a value.

Thats it.

Full Script

repeat wait() 
until
script.Parent:FindFirstChildOfClass("Decal") ~= nil 
	and script.Parent:FindFirstChildOfClass("Decal"):FindFirstChildOfClass("StringValue") == nil

--while true do
	wait(2)
	
	local f = Instance.new("StringValue")
	f.Name = "House"
	f.Value =  "b1"
	f.Parent = script.Parent:FindFirstChildOfClass("Decal")
--end

This script creates a string, but if I remove the created string, it doesnt create another one.

Another attempt just creates the string every 2 seconds.

2 answers

✓ Accepted answer

You can simply use 1 while loop.

while true do
	if script.Parent:FindFirstChild("Decal") then
		if not script.Parent.Decal:FindFirstChild("StringValue") then
			local newString = Instance.new("StringValue")
			newString.Value = "B1"
			newString.Parent = script.Parent.Decal
		end
	end
	wait(2)
end

This will just infinitely loop every 2 seconds checking if there's a string or not. If there isn't, it'll just create one and parent it.


If this helped, don't forget to mark it as an answer!

2 comments

0

Hey. It didn't work, but I managed to alter it a bit and it now works perfectly. :)

0

No problem! Glad to help.

I got it to work. :)

while true do
	if script.Parent:FindFirstChildOfClass("Decal") then
		if not script.Parent:FindFirstChildOfClass("Decal"):FindFirstChild("House") then
			local newString = Instance.new("StringValue")
			newString.Name = "House"
			newString.Value = "b1"
			newString.Parent = script.Parent:FindFirstChildOfClass("Decal")
		end
	end
	wait(2)
end

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