Problem with clock

So you’re saying that im stuck with a code that doesnt change the position of the part
even though thats the entire reason i created this topic

1 Like

Not exactly.
Im saying that your part is not changing position cause the code was not working as expected…
But. Thats easy to solve, the real and important stuff about this, is what is exactly the goal of your mechanics, would a loop is really needed? making it more efficient is something we dont aim for?
Those questions totally relies on your goals. As far as I understand you dont even need a loop to check what the player got after clicking.

Yes i really need a loop right now because the clock’s hour part doesnt change position

i dont need a code that only tells me that the player got it correct

thats why i needed the loops to pick an index from the array and set its values to the current position and orientation of the clock’s “hour” part

Screenshot_1

If thats the reason, no you dont. You have enough data to get that with these lines:

local random = possibleHourPositions[math.random(1, #possibleHourPositions)]

random.Position -- the pos
random.Orientation -- the rot

Those lines are the data from the specific random key choosen by the player clicking the button, enough to change the position of the PART that works as the “arrows” of the clock

To make it clearer, if you have a table, you have an index, and you know the name of the properties. And those properties holds something like a Vector3, or a CFrame. Then just access them and apply them to a part:

MyPart = TheClockHand -- the part that you wanna move

local random = possibleHourPositions[math.random(1, #possibleHourPositions)]
MyPart.Position = random.Position

so you want it to be like this?

script.Parent.hour.ClickDetector.MouseClick:Connect(function()
	local random = possibleHourPositions[math.random(1, #possibleHourPositions)]

	if  random["TheRightOne"] then
			script.Parent.hour.Position = random.Position
			script.Parent.hour.Orientation = random.Orientation
			script.Parent.ding:Play()
			screenColorModule.ScreenColor(game.Lighting.MeteorEffect,Color3.new(1, 1, 1),3,0)
		else
			script.Parent.hour.Position = random.Position
			script.Parent.hour.Orientation = random.Orientation
		
			
		end
	
end)


Yeah, kinda, first, the key I added is named “TheKey” and you are looking for a key named “TheRightOne”, meaning none of the keys has that name so, all tries will always end up in “not found” = false

Additionally I would prefer to do it like this:

local possibleHourPositions = {
	{ 
		Position = -69.618, 8.446, 0.064,
		Orientation = -28.17, 180, 0
	},
	{
		Position = -69.618, 7.827, 0.774,
		Orientation = -58.805, 180, 0
	},
	{
		Position = -69.618, 6.726, 1.153,
		Orientation = 90, 0, 0
	},
	{
		Position = -69.618, 7.796, -3.019,
		Orientation = -59.203, 0, 0
	},
	{
		Position = -69.618, 5.617, -3.173,
		Orientation = -61.884, 180, 180
	},
	{
		Position = -69.618, 4.527, -1.126,
		Orientation = 0, 0, 180
	},
	{
		Position = -69.618, 9.127, -1.126,
		Orientation = 0,0,0,
		TheRightOne = true
	}

}

-- The handling function
script.Parent.hour.ClickDetector.MouseClick:Connect(function()
	-- Select a random one
	local random = possibleHourPositions[math.random(1, #possibleHourPositions)]
	
	-- Set the position
	script.Parent.hour.Position = random.Position
	script.Parent.hour.Orientation = random.Orientation
	
	-- Check if its the golden one
	if  random["TheRightOne"] then
		script.Parent.ding:Play()
		screenColorModule.ScreenColor(game.Lighting.MeteorEffect,Color3.new(1, 1, 1),3,0)
	end
end)
2 Likes

oh and by the way the studio expected me to use vector 3 instead of random.Position
Screenshot_1

You can fix it by storing Vector3’s in your table:

local possibleHourPositions = {

	{ 
		Position = Vector3.new(-69.618, 8.446, 0.064)

EDIT: Consider using CFrames are way more useful

oh nice well this took longer than i thought it would be

1 Like

I tried using cframe and it really wants me to use vector3 y’know? i wasted my time again.

im really gonna give up if this doesn’t work again (gonna give you the solution for taking your time tho)

UPDATE: it finally worked.

1 Like

I’d like to thank you for your patience and time just gonna say that i suck at scripting and just started using tables or loops for my projects.

Goodbye.

1 Like

Hey, send a PM to me and I can help you, just NEVER give up, this is simple, you just need to continue until the end

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.