Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Randomly chosen positions? [SOLVED]

Asked by 9 years ago

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

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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

0
It works! Thank you. Grenaderade 525 — 9y
Ad

Answer this question