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

Can I make a looping script using values?

I'm trying to make a tv that can turn on and off for my game. The value turns to 1 but the texture isn't even changed. If i do

While true do
	 script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955416"
	wait(1)
	 script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955712"
	wait(1)
	 script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955930"
	
end

it works but i'm looking to do something like:

while workspace.tv.Value == 1 do

	 script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955416"
	wait(1)
	 script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955712"
	wait(1)
	 script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955930"
	
end

2 answers

✓ Accepted answer

The problem is that this code only runs once. So the game checks if the tv is on, and if it isn't on, it just ends the script and doesn't check ever again. Try using the event workspace.tv.Changed so every time the value changes, it checks if the tv should be on.

workspace.tv.Changed:Connect(function() --runs this function when the value changes
	while workspace.tv.Value == 1 do
		script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955416"
		wait(1)
		script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955712"
		wait(1)
		script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955930"
	end
end

You could use the "if" statement instead of the while for example

if workspace.tv.Value == 1 then
     script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955416"
    wait(1)
     script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955712"
    wait(1)
     script.Parent.Decal.Texture = "http://www.roblox.com/asset/?id=4908955930"
	else
end

2 comments

0

Thanks so much!

0

No Problem just remember to explain and put a script and we will help you.

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