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

How to create a Miner's Haven part movement?

Hi guys! I would like create a part follow cursor, so i know how to create that but not that... Somebody can explain me how ?

My script:

--< Services
local PlayerService = game:GetService('Players')
local TweenService = game:GetService('TweenService')
local UserInputService = game:GetService('UserInputService')

--< PlayerInfo
local Player = PlayerService.LocalPlayer
local Mouse = Player:GetMouse()

--< Functions
local function GetPosition(HitBox)
	local newX = Mouse.hit.p.x
	local newZ = Mouse.hit.p.z
	
	local Move = {}
	Move.CFrame = cframe(newX, 4.5, newZ)
	
	
	return Move
end

--< Events
UserInputService.InputChanged:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseMovement then
		TweenService:Create(HitBox, TweenInfo.new(.5), GetPosition(HitBox)):Play()
	end
end)

1 comment

0

Move is a table..

1 answer

I haven’t really done stuff like this, but you could try using math.floor on x and z. It rounds the number to the nearest whole number so it would look like it’ll stay on grid, instead of going off the grid when it’s a decimal number.

I think you’ll have to do something like this on line 16 :

Move.CFrame = cframe(math.floor(newX), 4.5, math.floor(newZ))

Or you can make separate variables with the rounded numbers if you want to.

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