Here’s what I have so far:
So far it goes to the position of the mouse
I want it to come closer to the player as they hold the E key and further as they hold the Q key. I’ve tried doing this myself, but I’ve had no luck.
My code where it tells the server where to position the enemy:
local holdingE = false -- e will make them move closer
local holdingQ = false -- q will make them move further
local enemyYPos
local enemyXPos
local enemyZPos
local tkDistance = 30
local tkMoveIncremement = .5
local lastposToSend
mouse.Move:Connect(function()
if holding == true then
local posToSend = Vector3.new(0, 0, 0)
local origin = player.Character.Head.Position
local direction = (mouse.Hit.Position - origin).Unit
local result = workspace:Raycast(player.Character.Head.Position, direction*tkDistance)
local intersection = result and result.Position or origin + direction*tkDistance
posToSend = intersection
local cameraDirection = workspace.Camera.CFrame.LookVector
if holdingE == true then
posToSend *= -posToSend * (cameraDirection*tkMoveIncremement)
elseif holdingQ == true then
posToSend *= posToSend * (cameraDirection*tkMoveIncremement)
end
script.Parent.mousePos:FireServer(posToSend)
end
end)