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

How do I convert a number to a vector3?

I'm trying to make a build tool that places bricks down and rounds them to the nearest whole position. I got a rounding script from my last question however I implemented it and got "Vector3 expected, got number" I was wondering if there's any way I could convert numbers into a vector3 here's what I have

function RoundNumber(Input) -- Input is whatever number you want to round
    local StringForm = tostring(Input)
    local PlacementOfDecimal = string.find(StringForm, ".")
    if tonumber(string.sub(StringForm, PlacementOfDecimal+1 ,PlacementOfDecimal+1)) >= 5 then
        return (tonumber(string.sub(StringForm, 0,  PlacementOfDecimal))) + 1
    elseif tonumber(string.sub(StringForm, PlacementOfDecimal+1 ,PlacementOfDecimal+1))<5 then
        return (tonumber(string.sub(StringForm, 0,  PlacementOfDecimal)))
    end
end

function cloneWood(hitTarget)
    local cloneTemp = game.Workspace.WoodBlock1
    local clonedWood = cloneTemp:Clone()
    clonedWood.Position = hitTarget
    clonedWood.Parent = game.Workspace
end
local tool = script.Parent
tool.Equipped:connect(function(Mouse)
    Mouse.Button1Down:connect(function()
        local hitTarget = Mouse.Hit
        local newTarg = RoundNumber(hitTarget)
        print(newTarg)
        cloneWood(newTarg) --once again, mouse.Hit.p or just set the CFrame
    end)
end)

2 comments

0

You can't, you have to use 3 numbers

0

How would I round a position then?

1 answer

✓ Accepted answer

On line 21, you have to make Mouse.Hit into a Vector3. Note that Mouse.Hit is a CFrame, so it does X, Y, and a Z, or three numbers that we can adjust into a Vector3. Line 21 in your code should look like this:

local newTarg = Vector3.new(RoundNumber(hitTarget.X), RoundNumber(hitTarget.Y), RoundNumber(hitTarget.Z))  

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