When I Spawn in this item it teleports to the wrong area

I made this minigame for one of the games where a pad gets cloned in from replicated storage and the player has to touch it to win, but when I moved it into replicated storage it spawns in way too far to the left. It worked when I had it under the normal workspace, but won’t work now that it is in replicated storage. Now it doesn’t even spawn in the right place when I put it under workspace. It is like it is spawning twice as far to the left as it should be.

Code:
image

General area it should spawn:

Where it is spawning but shouldn’t:

1 Like

Since this a model you need to get its bounding box by using the method: Model:GetBoundingBox() this returns a tuple value which gives both the pos and size, ofc you would be using the pos var and keep the random generation within the pos vector range.

I only have the part teleporting, it is in a model, but I don’t think that that should change where it spawns at based on where I have the script. I don’t know for sure though so can you explain a little more?
image

Well there’s two ways you can do this; firstly being what I said above (but only the bounds of the part), and lastly getting the bounds of an individual part without the use of methods like GetExtentsSize()/ GetBoundingBox() rather creating a function that does the boundary calculations (which I highly don’t suggest):

You need to take into account the boundaries of the part so it doesn’t leave it when spawning with random generation.

I don’t understand what any of that means because I am kinda new to all this, do you mind explaining it a little more?

So what we are gonna do here is spawn parts around the given radius of a circular part e.g; In this case you should check if the point is inside the circle by checking its distance from the center, and if it’s not inside discard it and generate a new point.

image

Reference Code:

-- Variables
local spawnCircle = script.Parent

local diameter = (spawnCircle.Size.Y + spawnCircle.Size.Z) / 2
local radius = diameter/2

for spawnAngle = 36, 360, 36 do
	print("spawnAngle = " .. spawnAngle)
	local xDifference = math.cos(math.rad(spawnAngle)) * (radius - radius/5)
	local zDifference = math.sin(math.rad(spawnAngle)) * (radius - radius/5)
	local newPoint = Vector3.new(spawnCircle.Position.X + xDifference, spawnCircle.Position.Y + 1, spawnCircle.Position.Z + zDifference)
	
	local newPart = Instance.new("Part")
	newPart.Parent = game.Workspace
	newPart.Name = "Spawn Angle: " .. spawnAngle
	newPart.Position = newPoint
	newPart.Color = Color3.new(0, 0, 0)
end

Should look like:

Ok, from you post I took from is that I should take the position of the bigger circle and add my ne random value to it and now it works. thx