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

How do I fix the error "Attempt to concatenate string with vector3?"

Asked by 3 years ago

Hello, I am trying to clone a part inside another part, and make that part have a random place. Here is my code:

01local smallRandom = math.random(10, 20)
02local mediumRandom = math.random(22, 35)
03local largeRandom = math.random(38, 50)
04 
05local x = script.Parent.Size.X/2
06local y = script.Parent.Size.Y/2
07local z = script.Parent.Size.Z/2
08 
09while true do
10    wait(smallRandom)
11    local smallclone = game.Workspace.SmallScraps:Clone()
12 
13    smallclone.Position = script.Parent.Position + Vector3.new(math.random(-x, x), math.random(-y, y), math.random(-z, z))
14 
15    smallclone.Anchored = false
16    print("Part Spawned at " ..smallclone.Position)
17end

When I run it, the part never spawns and an error appears saying "Attempt to concatenate string with vector3"

I got this code from another place and modified it to fit my game, so I don't know how to fix this error.

Thank you.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

change

1smallclone.Position = script.Parent.Position + Vector3.new(math.random(-x, x), math.random(-y, y), math.random(-z, z))

to

1smallclone.Position = script.Parent.Position * Vector3.new(math.random(-x, x), math.random(-y, y), math.random(-z, z))
0
I tried this out and the same error shows up. I looked at other forums and I think the solution might have something to do with tostring? Thank you for suggesting this answer, though. ImaginationPAYER 0 — 3y
0
i dont think tostring won't help because vector3 are vector and vector are numbers not strings WINDOWS10XPRO 438 — 3y
0
dm me on discord Blue Duck#8902 WINDOWS10XPRO 438 — 3y
Ad

Answer this question