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 randomly position my model?

So I have a balloon that's a model and I'm attempting to randomly spawn balloons all over my map. You can't get the position of a model itself so I've used mainPart. This script is not working and at this point I'm pretty much lost. Any help would be appreciated.

   local balloon = game.ServerStorage.TEST
   local startPosition = -30

local function createBalloonCopy ()
	local balloonCopy = balloon:Clone()	
	balloonCopy.Parent = game.Workspace	
	local xPosition = math.random(-64, 64)	
	local yPosition = math.random(-64, 64)	
	balloon.PrimaryPart = balloon:FindFirstChild("Head")--gets primary part of model	
	local Offset = balloon:GetPrimaryPartCFrame()--gets position of primary part i think?	
	balloonCopy.Offset = Vector3.new(xPosition, startPosition, yPosition)	
end

while true do	
	createBalloonCopy()	
	wait(5)
end

2 comments

0

looking at line 11, Model objects do not have a property called "Offset"

0

i think he set the offset as a cframe value so it's like a property replaced by a varibale, but it doesn't work that way, idk what he is trying to do

1 answer

✓ Accepted answer

I mean, this should be an easy fix, you just have a tiny problem with your script. You're attempting some weird stuff. Just keep it simple, instead of setting the ballon's primary part inisde the function after taking the copy. Do that manually in the already existing balloon inside ServerStorage. Set the PrimaryPart property (not via script) to the head. And since that's already set, the compied model each time will have the primary part set by default. And the rest should be easy.

local balloon = game.ServerStorage.TEST
local startPosition = -30

local function createBalloonCopy ()
		local balloonCopy = balloon:Clone()	
		balloonCopy.Parent = game.Workspace	
		local xPosition = math.random(-64, 64)	
		local yPosition = math.random(-64, 64)	
		
		balloonCopy.PrimaryPart.CFrame = CFrame.new(Vector3.new(xPosition, startPosition, yPosition))	
end

while true do	
	createBalloonCopy()	
	wait(5)
end

And for more info about CFrame go here.

2 comments

0

thank you for this and dealing with my code, I know it's a little messy haha.

0

Ty! No problem with that

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