Problem with tile movement system

No, im absolutely stumped

the only thing that it could be is that it’s a localscript and its trying to access the server workspace, but it can also get the target cords easy

1 Like

With what value does the Attribute be given to

The problem is cuz you can compare only numbers, use a Magnitude to get a lenght of a vector instead. I hope I help you :wink:

what do you mean???
explain more

this is the code now

local units = game.Workspace.Units:GetChildren()
local move = game.ReplicatedStorage.Remotes.Move

local selected = false

for _, unit in ipairs(units) do
	if unit:IsA("Model") and unit:FindFirstChildWhichIsA("Model") then
		local char = unit:FindFirstChildWhichIsA("Model")
		
		local hitbox = char:WaitForChild("Hitbox")
		local click = hitbox:WaitForChild("ClickDetector")
		local data = unit:FindFirstChild("Data")

		if click and data then
			click.MouseHoverEnter:Connect(function(plr)
				data.Extra.SelectionBox.Visible = true
			end)

			click.MouseHoverLeave:Connect(function(plr)
				if selected == false then
					data.Extra.SelectionBox.Visible = false
				end
			end)
			
			click.MouseClick:Connect(function(plr)
				selected = not selected
				data.Extra.SelectionBox.Visible = true
			end)
			
			local mouse = game.Players.LocalPlayer:GetMouse()
			
			mouse.Button1Down:Connect(function()
				if mouse.Target.Parent.Name == "Tiles" and mouse.Target:IsA("MeshPart") then
					local targetTile = mouse.Target
					local targetCords = targetTile:GetAttribute("Cords")
					
					local currentTile = data.CurrentTile
					local currentCords = currentTile:GetAttribute("Cords")
					
					--TODO move to server script
					local maxMove = data:GetAttribute("MoveRange")
					print(targetCords, currentCords, maxMove)
					if (targetCords.X <= maxMove.X) and (targetCords.Y <= maxMove.Y) and data.Owner.Value == game.Players.LocalPlayer.Name then
						char.HumanoidRootPart.Position = targetTile.Position + Vector3.new(0, 0.65, 0)
					end
				end
			end)
		end
	end
end

To get an Attribute you have to set one and give the attribute a value, just like how you did with your tile and max attribute

So like what is the value set to at server start?

its 2, 1

is it working now? Or still having a errors?

It’s not having any errors, it’s just printing the CurrentCords nil even tho it is clearly defined

my peanut brain forgot to put a .Value at the end of the currenttile value, so its fixed now lol

thanks for your time though

debug currentTile, maybe the ‘Cords’ attribute doesn’t exist? debug, data and etc.

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