Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

cursor that is supposed to move in the 3d world made with instance.new not moving?

Asked by 2 years ago

Hello! I'm trying to make a cursor that is a part move around in the 3d Roblox world, and then make it into a place box afterward so players see where they are placing items like traps, landmines, etc, Right now the problem is that the cursor spawns in, but it doesn't move and it just stays at 0,0,0. I scanned through the console but I didn't find anything related to this script.

I've tested this in studio, and in the experience, the same result it doesn't move. Attempts: I've tried to optimize the code and remove while true loops, I went from using x, y to .hit after looking at some documentation, but other than that I am totally lost.

cursorstorage = a folder in the workspace.

This script is in a tool, in workspace.

This script is a local script.

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

script.Parent.Equipped:Connect(function()
    local cursor = Instance.new("Part")
    cursor.Color = Color3.fromRGB(255, 255, 255)
    cursor.Material = Enum.Material.Neon
    cursor.Size = Vector3.new(0.5, 0.5, 0.5)
    cursor.Transparency = 0.5
    cursor.Parent = game.Workspace.cursorstorage
    cursor.Anchored = true
    cursor.Name = ("Cursor")
    mouse.Move:Connect(function(moved)
        cursor.Position = Vector3.new(mouse.Hit.Position)
    end)
end)


script.Parent.Unequipped:Connect(function()
    if game.Workspace.cursorstorage:FindFirstChild("Cursor") then
        game.Workspace.cursorstorage.Cursor:Destroy()
    end
end)


Any help is appreciated! full solutions to just suggestions to clean up my code, make it more optimized, or just thoughts on how it could be fixed, Thank you.

1 answer

Log in to vote
1
Answered by
Befogs 113
2 years ago

Your Vector3 position is mouse.Hit.Position, and what you're doing is passing that as an arguement to Vector3.new and using that vector. Passing a Vector3 into Vector3.new is just going to return Vector3.zero. Your solution would be to use the mouse's position without passing it into a new vector, like so:

cursor.Position = mouse.Hit.Position

0
Oh thank you so much! asmetics 26 — 2y
Ad

Answer this question