To expand upon my other answered question, I want to teleport someone who clicks a text button to a random area on the baseplate that I specify (i.e. a spawn point ). I want to try a table and pull random values from that, but I'm not sure that it will work.
The current code I have and want to edit is below.
bin = script.Parent Part = game.Players.LocalPlayer.Character function onClick() if Part.FindFirstChild("Torso") then Part.Torso.CFrame = CFrame.new(Vector3.new(6, -28, 2) end end bin.MouseButton1Click:connect(onClick)
If you could, please comment the changes you made to the script, and highlight the things I did wrong. Thanks in advance.
I fixed your mistakes, you put .FindFirstChild when FindFirstChild is a method, therefore it needs ':', so :FindFirstChild, also you were missing a ')' after the line with Part.Torso.CFrame.
Also change the base variable to the place you want them to spawn to!
bin = script.Parent Part = game.Players.LocalPlayer.Character Base = Workspace.BasePlate function onClick() if Part:FindFirstChild("Torso") then local MinX = Base.Position.X-(Base.Size.X/2) local MaxX = Base.Position.X+(Base.Size.X/2) local MinZ = Base.Position.Z-(Base.Size.Z/2) local MaxZ = Base.Position.Z+(Base.Size.Z/2) Part.Torso.CFrame = CFrame.new(Vector3.new(math.random(MinX,MaxX), Base.Position.Y+3, math.random(MinZ,MaxZ))) end end bin.MouseButton1Click:connect(onClick)
bin = script.Parent Part = game.Players.LocalPlayer.Character function onClick() if Part:FindFirstChild("Torso") then Part.Torso.CFrame = CFrame.new(Vector3.new(6, -28, 2) end end bin.MouseButton1Click:connect(onClick)