So, I’ve been trying to make this script where when a player clicks on a TextButton, they are “teleported” via CFrame to a new position.
Essentially, players can press on a “TP to obby” button that teleports them to an obby. When players click on the TP button, they land on a specific part. As long as players stand on that specific part, a TextButton and a TextLabel are visible. The only way to close the TextButton and TextLabel is by pressing the TextButton, but I’d like players to also be teleported to a new position when they press the TextButton.
Here’s my issue: I made a Local Script under StarterGui, and it doesn’t work. No errors in the output. I’m not really sure what to do.
Here’s the script:
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos
--buttons--
local tpbutton = player.PlayerGui.ScreenGui.TextButton
tpbutton.Activated:Connect(function()
player.Character.LowerTorso.CFrame = CFrame.new(tphere.Position)
end)
I’ve tried by using MouseButton1Click instead of .Activated, but it didn’t change nothing. It just doesn’t want to TP the LocalPlayer.
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos
--buttons--
local tpbutton = player.PlayerGui.ScreenGui.TextButton
tpbutton.Activated:Connect(function()
player.Character.LowerTorso.CFrame = CFrame.new(tphere.Position)
print("TP Worked")
end)
Updated script^
When I press on the “close” button, nothing prints.
EDIT: Also do me a favor and add a print at the beginning of the script to make sure the scripts runs. I know local scripts should run from inside PlayerGui, but just to be sure. Maybe they need to be inside a ScreenGui or something.
print("This is inside PlayerGui")
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos
--buttons--
local tpbutton = player.PlayerGui.ScreenGui.TextButton
tpbutton.Activated:Connect(function()
player.Character.LowerTorso.CFrame = CFrame.new(tphere.Position)
print("TP Worked")
end)
print("This is inside PlayerGui")
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos
--buttons--
local tpbutton = player.PlayerGui.ScreenGui.TextButton
tpbutton.Activated:Connect(function()
player.Character:SetPrimaryPartCFrame(tphere.CFrame)
print ("TP worked")
end)
and
print("This is inside PlayerGui")
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos
--buttons--
local tpbutton = player.PlayerGui.ScreenGui.TextButton
tpbutton.MouseButton1Click:Connect(function()
player.Character.HumanoidRootPart.CFrame = tphere.CFrame
print ("TP worked")
end)
print("This is inside PlayerGui")
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos
--buttons--
local tpbutton = script.Parent:WaitForChild("TextButton")
tpbutton.MouseButton1Click:Connect(function()
player.Character.HumanoidRootPart.CFrame = tphere.CFrame
print ("TP worked")
end)
However, upon testing it works 1/5. Should I add wait() or something similar so it works all the time?