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

When I use Mouse.Hit.p it keeps going towards my camera? (Any Fix?)

When I use Mouse.Hit.p the part that was created keeps moving towards my camera?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
	if key == "1" then
		--//Magnet Release\\--
		if script.Parent.Jutsu.Value == "SandManipulation" then
			local MoveableSand =  game.ReplicatedStorage.Test:Clone()
			MoveableSand.Parent = game.Workspace
			wait(0.1)
			mouse.Button1Down:connect(function()
				for i = 1, 1000 do
					wait(0.01)
					MoveableSand.Position = mouse.Hit.p
				end
			end)
		end

Please help?

2 comments

0

It's the correct behaviour of Mouse.Hit.p; you create the part in the mouse's position, and the part's position becomes the mouse's position. You could try using a condition to ignore the part that was created.

0

also mouse.KeyDown is deprecated and works unreliably, use UserInputService instead.

1 answer

✓ Accepted answer

Try this version of the script. Just changed 2 lines that i noted.


local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
    if key == "1" then
        --//Magnet Release\\--
        if script.Parent.Jutsu.Value == "SandManipulation" then
            local MoveableSand =  game.ReplicatedStorage.Test:Clone()
            MoveableSand.Parent = game.Workspace
            wait(0.1)
            mouse.Button1Down:connect(function()
                for i = 1, 1000 do
                    wait(0.01)
                     if mouse.Hit.Name ~= "MODELNAMEHERE" then  --Add this
                    MoveableSand.Position = mouse.Hit.p
                   end -- And this
                end
            end)
        end

2 comments

0

mouse.hit is the position of the house, not mouse.Target ;-;

0

It doesn't work, but thanks for the help!

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