I’m making a trying to make a fighting game as one of my projects, and I am at the point where I need to script the npc ai’s movement and I put invisible wall so the npc doesn’t leave the fight ground, the problem is I’m trying to make the noob not go past a certain position like Vector3.new(12,0,0) but the npc is always passing it by just a little bit so instead of it’s max position on the x axis being 12 it’s 12.542357 so that means it can touch the invisible wall and knock the noob out of the correct position on the z axis.
The video - YouTube
It’s been a week trying to figure this out
Here’s the script
local noob = game.Workspace:WaitForChild(“Dummy”)
local hrp = noob:WaitForChild("HumanoidRootPart")
local hum = noob:WaitForChild("Humanoid")
local botPressed = script.Parent.BotPressed
local runservice = game:GetService("RunService")
local move = coroutine.create(function()
while task.wait() do
botPressed.Changed:Wait()
if botPressed.Value == "LeftButton" then
while task.wait() do
if hrp.Position.X <= -9.5 then
print("noob to the left")
print(hrp.Position.X)
break
else
if botPressed.Value == "Lifted" then
print("Lifted")
break hum:Move(Vector3.new(-0.5,0,0))
end
print("moving")
end
end
end
if botPressed.Value == "RightButton" then
while task.wait() do
if hrp.Position.X >= 12.5 then
print("noob to the Right")
print(hrp.Position.X)
break
else
if botPressed.Value == "Lifted" then
print("Lifted")
break hum:Move(Vector3.new(0.5,0,0))
end
print("moving")
end
end
end
end
end)
coroutine.resume(move)
while task.wait(1) do
local randomNum = math.random(3,10)
botPressed.Value = "LeftButton"
task.wait(randomNum)
botPressed.Value = "Lifted"
task.wait(1)
local randomNum = math.random(3,10)
botPressed.Value = "RightButton"
task.wait(randomNum)
botPressed.Value = "Lifted"
end```