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

how to set the position of a block using cframe when cloning using math.random?

I keep trying to set the position of a block when it is clones but it keeps giving me this error.

Workspace.PaintBall.Action1:13: invalid argument #2 to 'random' (interval is empty)

script:

local clonesneeded = 50 --how many clones are needed of each type

local function ends()
	game.Workspace.PaintBall.Action1.Disabled = true
end

while script.Disabled == false do
	while clonesneeded >= 1 do
		local v1clones = script.ClonesV1:Clone()
		v1clones.Parent = game.Workspace.PaintBall
		v1clones.Name = "clonesV1"
		v1clones.Transparency = 0
		v1clones.Position = Vector3.new(math.random(-70.875, -605.875), 5.473, math.random(-310.375, 260.125)) -- this line has the error
		
		local v2clones = script.ClonesV2:Clone()
		v2clones.Parent = game.Workspace.PaintBall
		v2clones.Name = "clonesV2"
		v2clones.Transparency = 0
		v2clones.Position = Vector3.new(math.random(-70.875, -605.875), 5.473, math.random(-310.375, 260.125))
		
		clonesneeded = clonesneeded - 1
		
	end
end

4 comments

0

I dont know if it needs a CFrame or not but I do not think it does.

0

math.random integers only. v1clones.Position = Vector3.new(math.random(stuff),math.random(stuff),5.473)

0

thanks!

0

I just tested it out and it still has the same error

1 answer

✓ Accepted answer
local clonesneeded = 50 --how many clones are needed of each type

local function ends()
	game.Workspace.PaintBall.Action1.Disabled = true
end

for i = 1, clonesneeded do
	if not script.Disabled then
		local v1clones = script.ClonesV1:Clone()
		v1clones.Parent = game.Workspace.PaintBall
		v1clones.Name = "clonesV1"
		v1clones.Transparency = 0
		v1clones.Position = Vector3.new(math.random(-605.875, -70.875), 5.473, math.random(-310.375, 260.125))

		local v2clones = script.ClonesV2:Clone()
		v2clones.Parent = game.Workspace.PaintBall
		v2clones.Name = "clonesV2"
		v2clones.Transparency = 0
		v2clones.Position = Vector3.new(math.random(-605.875, -70.875), 5.473, math.random(-310.375, 260.125))
	else
		break
	end
end

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