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

[Player CFrame] Random Points Help?

Teleporting to a random point on clicked!

points = game.Workspace.Points:GetChildren()
randPoint = math.random(1,#points)
player = script.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
	player.Character.Torso.CFrame = player.Character.Torso.CFrame(randPoint.Position)
end)

1 answer

✓ Accepted answer

Your problem is that you're just getting a random number between 1 and the number of children in 'Points'. You're not actually getting one of the parts. You have to index the 'points' table with the random number to get your part(:

Also, define the random point INSIDE the scope of the MouseButton1Click event, that way it will be random everytime you click.

Use a localscript, and use game.Players.LocalPlayer to get the player.

local points = workspace.Points:GetChildren()
local plr = game.Players.LocalPlayer --get player

script.Parent.MouseButton1Down:connect(function()
	local randPoint = points[math.random(1,#points)] --index with random number
	plr.Torso.CFrame = randPoint.CFrame * CFrame.new(0,3,0)
end)
	

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