So Im trying to make it, so my game waits 5 seconds, then teleports the player to one of two bricks. This is the script i have:
locations = {"26, 0.5, -1", "26, 0.5, -33"} locationselected = locations [math.random(1, #locations)] while true do wait(5) game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Head.CFrame = CFrame.new(locationselected) end
But it's saying "Vector3 Expected, got string"
Any help?
You cannot set CFrames of instances using strings, you must use Vector or CFrame values.
Also, I'm not sure if this is in a local script or a server script because the code is entirely wrong, if you're using a server script you cannot index the player in a server script using game.Players.LocalPlayer, but if your using a local script you can, but you cannot change a CFrame in a local script in FilteringEnabled because it won't replicate to the server.
I would suggest just keeping a table of Vector3 or CFrame values (I prefer CFrame) and set the CFrame or Position to that value in the table.
local Tab = {CFrame.new(26, 0.5, -1); CFrame.new(26, 0.5, -33)} local locationselected = Tab[math.random(1, #Tab)] while wait(5) do head.CFrame = locationselected -- sample code end
Alternatively, you can also use the new Random.new() function which is much more efficient and has more uses.
local Tab = {CFrame.new(1,1,1); CFrame.new(2,2,2)} local rng = Random.new() local function returnCFrame() local result = rng:NextInteger(1, #Tab) return Tab[result] end while wait(5) do local partCFrame = returnCFrame() head.CFrame = partCFrame- end
If you have any more questions don't hesitate to ask :D