Limit To Part Position

Hello Developers. Currently, I am working on a game somewhat like Power Slap. Overall the process of developing the game has gone good but I’ve ran into problem that’s very very much bothering me.

You are allowed to just move the part everywhere making it so that the IkControl im using does weird stuff. And I want to add a position limit on the X-Axis that can be exceeded to prevent that.

How could I achieve something like this?

A Little Video Explaining The Issue:

Code:

local function MousePart()
	local Part = Instance.new('Part',workspace)
	-- Set Settings / Part --
	Part.Size = Vector3.new(1,1,1)
	Part.Material = Enum.Material.SmoothPlastic
	Part.Anchored = true
	Part.CanCollide = false
	Part.Position = Character:WaitForChild('Head').Position
	-- While Statement --
	while true do
		task.wait()
		Part.Position = Vector3.new(LocalMouse.Hit.X,Part.Position.Y,Part.Position.Z)
	end
end
2 Likes

First off, using Instance.new(instance, parent) is deprecated, switch to setting the parts parent outside of the instance.New thing

Second, you would probably want to check if the LocalMouse.Hit.X variable exceeds whatever number.

You could do something like,

if LocalMouse.Hit.X < 15 and LocalMouse.Hit.X > -15 then
2 Likes

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