Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a block move to a player at a fixed speed? [SOLVED]

This is my code:

local maths = 10
local limb = "Head"
wait(5)
repeat
	local p1 = script.Parent.nearest.Value
	if p1 ~= "nil" then
		local player = game.Workspace[p1]
		local pos = script.Parent.Position
		local ppos = player[limb].Position
		-- X
		local x1 = pos.X - ppos.X
		local x2 = x1 / 10
		-- Y
		local y1 = pos.Y - ppos.Y
		local y2 = y1 / 10
		-- Z
		local z1 = pos.Z - ppos.Z
		local z2 = z1 / 10
		-- hunt down the player
		
		script.Parent.energy.Value = script.Parent.energy.Value - 1	 	
 		script.Parent.Position = script.Parent.Position - Vector3.new(x2,y2,z2)
		
	end
	wait(0.01)
until nil

The problem here is, no error, is that it makes the brick move to the player, but since it divides the distance by 10 it will get slower as it gets closer to the player, and faster as the player moves away, making an infinite stalemate if the player walks away. I was wondering if a fixed speed was possible.

Is there a CFrame property I'm missing?

1 answer

Fixed, I'm gonna use bodyposition.

1 comment

0

Yeah body postion is the way to go, it has MaxVelocity property.

This discussion is preserved as it was. New answers, comments, and votes are closed.