NumberValue amount won't change

Hello, I was making a TicTacToe field. I made a value called TurnValue. It’s supposed to change whenever a block is clicked. For example: Let’s say a block becomes an X. Any other block clicked will become an O; Because the TurnValue changed. But in my situation, it doesn’t want to change.

Screenshots for further information

Sorry if the programming is really bland and unprofessional.

1 Like

I believe the issue is because you also used .Value in the variable that gets the TurnValue (in the first line). Remove that and you should be fine.

Hey! I got some ideas how to fix it.
First: replace "local TurnValue = script.Parent.Parent.Parent.TurnValue.Value" to "local TurnValue = script.Parent.Parent.Parent.TurnValue". Do not forget to add a “.Value” after TurnValue.

Second: Write a direct path to the TurnValue. For example “local TurnValue = game.Workspace.TurnValue

Hope it will work. Have a good time !

Ok, I’ll check. Let’s hope this works.

1 Like

Should have mentioned this earlier, you also need to add .Value within the MouseClick function to check the current value of TurnValue.

Also, to make your code more simple, and rather than having to use a script for each button, you should use a for loop to get all the click detectors at once, and detect if one of them get’s clicked (in just one script).

Place a script right under the TicTacToe model, then use the following code below (disable the other scripts as well):

local MainModel = script.Parent
local TurnValue = MainModel:WaitForChild("TurnValue")
local IsPlayed = MainModel:WaitForChild("isPlayed")

for _, cDetector in pairs(MainModel:GetDescendants()) do
	if cDetector:IsA("ClickDetector") then
		cDetector.MouseClick:Connect(function(plr)
			local XandOModel = cDetector.Parent:FindFirstChildWhichIsA("Model")

			if plr then
				if TurnValue.Value == 0 then
					XandOModel.X.Transparency = 0
					XandOModel.O.Transparency = 1
					TurnValue.Value = 1
				else
					XandOModel.X.Transparency = 1
					XandOModel.O.Transparency = 0
					TurnValue.Value = 0
				end
			end
		end)
	end
end
1 Like

That didn’t work either. ---------

I’m pretty sure it should. Have you placed this script right under the TicTacToe model? Did you disable every other script under that specific model? Any errors or warnings in the output?

First: replace "local TurnValue = script.Parent.Parent.Parent.TurnValue.Value" to "local TurnValue = script.Parent.Parent.Parent.TurnValue". Do not forget to add a “.Value” after TurnValue.

Second: Write a direct path to the TurnValue. For example “local TurnValue = game.Workspace.TurnValue

Have you tried these two methods? Btw, I’m pretty sure the BabyNinjaTime code should work. Did you follow his instructions?

Place a script right under the TicTacToe model, then use the following code below (disable the other scripts as well):

2 Likes

No errors in the output. I placed the script under the TicTacToe model as you can see:
image

1 Like

Try adding print statements in the script to see which part of the code runs and which doesn’t. Let me know the results after.

Ok, gonna do that right now. --------

Yes. ---------------------------------------

The entire script doesn’t work.
image

I just realized I misspelled the isPlayed value as IsPlayed (with a capital i), which is likely why the script wasn’t working. I have updated the code in my second post above.

Wow, It worked perfectly. thank you!

2 Likes

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