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

How do I convert a number to a vector3?

Asked by 7 years ago

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

01function RoundNumber(Input) -- Input is whatever number you want to round
02    local StringForm = tostring(Input)
03    local PlacementOfDecimal = string.find(StringForm, ".")
04    if tonumber(string.sub(StringForm, PlacementOfDecimal+1 ,PlacementOfDecimal+1)) >= 5 then
05        return (tonumber(string.sub(StringForm, 0,  PlacementOfDecimal))) + 1
06    elseif tonumber(string.sub(StringForm, PlacementOfDecimal+1 ,PlacementOfDecimal+1))<5 then
07        return (tonumber(string.sub(StringForm, 0,  PlacementOfDecimal)))
08    end
09end
10 
11function cloneWood(hitTarget)
12    local cloneTemp = game.Workspace.WoodBlock1
13    local clonedWood = cloneTemp:Clone()
14    clonedWood.Position = hitTarget
15    clonedWood.Parent = game.Workspace
View all 25 lines...
0
You can't, you have to use 3 numbers Leamir 3138 — 7y
0
How would I round a position then? ExtremeNyanCat123 32 — 7y

1 answer

Log in to vote
2
Answered by
zyrun 168
7 years ago

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:

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

Answer this question