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

How Could I Change a Part's Velocity to Match a User's Mouse Location?

This may be more difficult than it sounds. Let's assume a user creates a part through a global script. Is there a way to make that part move in the direction of that user's mouse.Hit.p until the part no longer exists? I have been trying many things, but here is my latest attempt. If anyone knows how to do this, I would be extremely grateful! Thanks in advance.

In a local script within the part that was created...

player = game.Players.LocalPlayer
while wait(.01) do
	if script.Parent ~= nil then
		local mouse = player:GetMouse()
		local position = mouse.Hit.p
		script.Parent.Velocity = CFrame.new(script.Parent.Position, position) * 70
	end
end

2 comments

0

I dont think you can use a CFrame for Part.Velocity. According to the Wiki at least, it takes a Vector3. In that case, I would just do Part.Velocity = Mouse.Hit.Position.

0

I initially had .LookVector appended to the end on line 6 after the parentheses. That didn't work either.

1 answer

you need to use a body mover or this will never work, you cant change velocity directly, velocity is just the effect. to change velocity you need to use a bodyvelocity and from this you can do ~~~~~~~~~~~~~~~~~ bodyvelocitypath.MaxForce = Vector3.new(math.huge,math,huge,math.huge) bodyvelocitypath.Velocity = Vector3.new(mouse.Hit.p)


3 comments

1

Just to note you can change velocity directly. It will only apply the velocity for a small time and gravity will stop it, unless being applied constantly in a loop or runservice connection

0

no velocity is just the effect and cannot be changed directly

0

This didn't work...

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