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

My script isn't changing it's decal?

This script is suppost to randomize itself then choose a decal but it doesn't. Could anyone help me with this issue?

for i,v in pairs(script.Parent.Screens:GetChildren()) do
	while wait(math.random(0.5 ,1)) do
		local textures = {
			"rbxassetid://1015850667",
			"rbxassetid://912712159",
			"rbxassetid://912695512",
		}
		local chosenAd = math.random(1, #textures)
		v.Decal.Texture = chosenAd
	end
end

1 answer

✓ Accepted answer

You're making the texture a number. Index the table with the random value.

v.Decal.Texture = textures[chosenAd]

Actually fixing the script

The while loop will never break, and so only one decal will ever change. Move the while loop outside of the generic for loop to make this work properly. However, I'll be using spawn in my example, along with making a few other changes. Feel free to ask me if you're confused, or let me know if something doesn't work.

local textures = {
	"rbxassetid://1015850667",
	"rbxassetid://912712159",
	"rbxassetid://912695512",
}

for _,v in pairs(script.Parent.Screens:GetChildren()) do
	spawn(function()
		while wait(1-math.random()/2) do
			local chosenAdIndex = math.random(#textures)
			v.Decal.Texture = textures[chosenAdIndex]
		end
	end)
end

Good Luck!

2 comments

0

There is a error at line 14.

0

Fixed.

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