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

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

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

local smallRandom = math.random(10, 20)
local mediumRandom = math.random(22, 35)
local largeRandom = math.random(38, 50)

local x = script.Parent.Size.X/2
local y = script.Parent.Size.Y/2
local z = script.Parent.Size.Z/2

while true do 
	wait(smallRandom)
	local smallclone = game.Workspace.SmallScraps:Clone()

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

	smallclone.Anchored = false
	print("Part Spawned at " ..smallclone.Position)
end

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

change

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

to

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

3 comments

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.

0

i dont think tostring won't help because vector3 are vector and vector are numbers not strings

0

dm me on discord Blue Duck#8902

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