So in my game i have a set of attributes in every tile, that when the user clicks on a direction on the dpad, the tile should move and change the coordinate attributes.
The tile does move properly, however the attribute does not seem to be updating.
left.MouseButton1Click:Connect(function()
if clicked == false then
print(clicked)
ss["Flashlight Click"]:Play()
print('y = ',currenty)
print('x = ',currentx)
if currentx > 1 then
goal = {Position = tile.Position + Vector3.new(0,0,1)}
end
tile:SetAttribute('xcord',tile:GetAttribute('xcord') - 1)
local tween = tweenserv:Create(tile,tweeninf,goal)
tween:Play()
clicked = true
wait(0.5)
clicked = false
end
end)
So the variable tile is the value of an object value that holds the value of that specific tile, so i was thinking that could be the problem.
It can be called both from the server and the client however the server will only react to changes it makes and any changes from the client will not affect the server. However I can see that your script is working fine, the reason it is printing the same is maybe because currentX and currentY are the same every time? Could you print out tile:GetAttribute("xcord") instead
You most likely have currentx and currenty set to the result of a one-time GetAttribute call. This does not create a shortcut to the attribute, but instead reports on the value of the attribute at that moment in time. Since you do not make any subsequent reassignments, the values will remain the same.
What you’ve encountered is the affect of reference types and value types. Very few things in Luau are reference types. Among those things are tables, instances, and functions. Assigning one variable to another containing a reference type will create make that new variable an alias, meaning it will show changes made through the other variable. Value types does not exhibit this behaviour, and are therefore unique copies of data.
When working with value-types, you must read and write to the value itself. This means each time you wish to know the current x and y values, you must call GetAttribute