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

Randomly chosen positions? [SOLVED]

I tried to make a random position script inside a part to go into randomly chosen CFrames that are being held in a variable.

positions = "-5.8, 0.1, -11.3" , "8.2, 0.1, -25.3" , "-25.8, 0.1, -14.7" , "8.6, 0.1, 6.3"
while true do
	wait(1)
	script.Parent.CFrame = Vector3.new(1, #positions)
end

It doesn't seem to work though, every time I use Vector3 instead of CFrame, it says this in the output:

Workspace.BUX.Teleporter:4: bad argument #3 to 'CFrame' (CFrame expected, got userdata)

When I use CFrame instead of Vector3, I get this:

Workspace.BUX.Teleporter:4: bad argument #1 to 'new' (Vector3 expected, got number)

I made an alternative script, but people can cheat the game by staying in the same place:

while true do
	script.Parent.CFrame = CFrame.new(-5.8, 0.1, -11.3)
	wait(1)
	script.Parent.CFrame = CFrame.new(8.2, 0.1, -25.3)
	wait(1)
	script.Parent.CFrame = CFrame.new(-25.8, 0.1, -14.7)
	wait(1)
	script.Parent.CFrame = CFrame.new(8.6, 0.1, 6.3)
	wait(1)
	script.Parent.CFrame = CFrame.new(-25.8, 0.1, -14.7)
	wait(1)
	script.Parent.CFrame = CFrame.new(-5.8, 0.1, -11.3)
	wait(1)
	script.Parent.CFrame = CFrame.new(8.2, 0.1, -25.3)
	wait(1)
end

1 answer

✓ Accepted answer

It looks like you're trying to make a Table in line 1.

Line 4 has two errors: CFrame properties will error if you give them Vector3 Values, which you're trying to do, and math.random is the function you use for random numbers:

positions = {CFrame.new(-5.8, 0.1, -11.3) , CFrame.new(8.2, 0.1, -25.3) , CFrame.new(-25.8, 0.1, -14.7) , CFrame.new(8.6, 0.1, 6.3)}
while true do
    wait(1)
    script.Parent.CFrame = positions[math.random(1, #positions)]
end

1 comment

0

It works! Thank you.

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