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

Why isn't my GUI Button teleport the player random?

Recently I've been messing around with GUI Buttons in scripting and decided to do a random teleport. I had another place where I was working on but decided to open a new studio instance and play around with it. The teleport worked but now it isn't. How do I fix it?

It says Torso is not a part of the Model and I don't now what it exactly means.

local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 25, 0, 300)
textButton.Size = UDim2.new(0, 150, 0, 50)
textButton.BackgroundColor3 = BrickColor.White().Color
textButton.Text = "Random Teleport"
		
	textButton.MouseButton1Down:Connect(function()
	game:GetService('UserInputService')
	game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(Vector3.new(Random, Random, Random))
	textButton.Visible = false
		
end)

5 comments

0

i dont think connect is capitalized

0

it worked with it being capitalized on the other place

0

The error pretty much tells you everything. “Torso” doesn’t exist in the player’s character. Your script should work with R6 characters only, but if you’re using R15 too, use HumanoidRootPart instead.

0

also, this isnt FE compatable

0

Are you using R15 rig or R6? The errors tells yoy it cant find anything named Torso. The model is the player model in Workspace when you play. If your rig is R15 there are "UpperTorso"&"LowerTorso". R6 has just Torso.

1 answer

✓ Accepted answer

While testing this script, it seems the (Random, Random, Random) always just put me in the same position I already am.

Since you want to teleport a player, presumably within a map, you can use the GetExtents() Property of models to help generate a random placement with math.random()

Local Script

local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 25, 0, 300)
textButton.Size = UDim2.new(0, 150, 0, 50)
textButton.BackgroundColor3 = BrickColor.White().Color
textButton.Text = "Random Teleport"

textButton.MouseButton1Down:Connect(function()
	local extent = workspace.Model:GetExtentsSize()
	local random1 = math.random(-(extent.X)/2, (extent.X)/2)
	local random2 = math.random(-(extent.Y)/2, (extent.Y)/2)
	local random3 = math.random(-(extent.Z)/2, (extent.Z)/2)
	game.Players.LocalPlayer.Character:SetPrimaryPartCFrame(CFrame.new(random1, random2, random3))
	textButton.Visible = false
end)

Using the SetPrimaryPartCFrame() is better so that it will work for all players, regardless of their rigtype (R6 / R15)

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