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

Why isn't this script moving my ImageLabel correctly?

Why isn't this script moving my ImageLabel correctly?

What I want it to do is to select a random position(based on the values the ImageLabel has as descendants),until a certain value is equal to another value, but it won't, it will only move 1 time.. why?

Any help is greatly appreciated!

The ImageLabel - movement starts at line 57

My code is as follows:

local RS = game.ReplicatedStorage
local ItemFolder = RS:WaitForChild("Items")
local Items = ItemFolder:GetChildren()
local Player = game.Players.LocalPlayer
local PlrGui = Player:WaitForChild("PlayerGui")
local BoxGui = PlrGui:WaitForChild("BoxGui")
local Arrow = BoxGui.Frame.Arrow
local ArrowPositions = Arrow:GetChildren()
local CurrentPos = Arrow.pos1.Value

local Label1 = BoxGui.Frame:FindFirstChild("1")
local Label2 = BoxGui.Frame:FindFirstChild("2")
local Label3 = BoxGui.Frame:FindFirstChild("3")
local Label4 = BoxGui.Frame:FindFirstChild("4")
local Label5 = BoxGui.Frame:FindFirstChild("5")


script.Parent.MouseButton1Click:connect(function()
	
	---///SELECT RANDOM "ITEMS"
	local TimesToMove = math.random(7,14)
	print(TimesToMove)
	local Moved = 0
	
	local One = Items[math.random(1,#Items)]
	Label1.Text = One.Value
	
	local Two = Items[math.random(1,#Items)]
	if Two == One then 
		repeat Two = Items[math.random(1,#Items)] 
		until Two ~= One
	end
	Label2.Text = Two.Value
	
	local Three = Items[math.random(1,#Items)]
	if Three == One or Three == Two then 
		repeat Three = Items[math.random(1,#Items)] 
		until Three ~= One and Three ~= Two 
	end
	Label3.Text = Three.Value
	
	local Four = Items[math.random(1,#Items)]
	if Four == One or Four == Two or Four == Three then 
		repeat Four = Items[math.random(1,#Items)] 
		until Four ~= One and Four ~= Two and Four ~= Three
	end
	Label4.Text = Four.Value
	
	local Five = Items[math.random(1,#Items)]
	if Five == One or Five == Two or Five == Three or Five == Four then 
		repeat Five = Items[math.random(1,#Items)] 
		until Five ~= One and Five ~= Two and Five ~= Three and Five ~= Four  
	end	
	Label5.Text = Five.Value
	
	
	---///START ARROW MOVEMENT
	repeat 
		local Position = ArrowPositions[math.random(1,#ArrowPositions)]
		if Position.Value == CurrentPos then
			repeat
				local Position = ArrowPositions[math.random(1,#ArrowPositions)]
			until Position.Value ~= CurrentPos
		end
		Arrow.Position = UDim2.new(Position.Value)
		CurrentPos = Position.Value
		Moved = Moved + 1
	until Moved == TimesToMove
	
	
end)

1 comment

1

Your problem is that you have no yields, so it repeats and finishes all the movements faster than your computer can display that (or even that you'd be able to see for that matter). Just add in a wait() somewhere in the repeat loop, or add some kind of condition that it need to fulfill before looping, and it should work how you want it to.

1 answer

If you looked at your loop you'll see that it executes the code as fast as it can, and you can't display it fast enough. The way you get around that is with a simple wait(1000/fps), such as wait(1000/60) would be running 60 times a second, or every 16.67 ms

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