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.
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”
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
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):
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.