Still have questions? Join our Discord server and get real time help.
0

# TextButton script to teleport players isn't working? (inside a part)

I made a Surface gui inside a part and then made a TextButton inside it because that's how part gui's work. Anyways I placed the script that always worked in normal StarterGui GUI's but it isn't working inside a part gui. Can you help me please?

local debounce = true
local player = game.Players.LocalPlayer -- The player
local target = game.Workspace:WaitForChild("Practiceobby") --Part that player will get teleported to.

script.Parent.MouseButton1Click:Connect(function()
if debounce == true then
debounce=true
script.Parent.ClickSound:Play()
player.Character.HumanoidRootPart.CFrame = target.CFrame*CFrame.new(0,3,0)
-- Teleporting the player... but doesn't work ):
debounce = true
end
end)


Type of script is a LocalScript

game.Workspace.Part.SurfaceGui.TextButton.LocalScript

0
Also you might want to change it to a regular script brodywth 45 — 9d
0
ok ZombieApocalypz3 22 — 9d
0
LocalScripts don't run in Workspace. uhi_o 417 — 8d

0
Edited 9 days ago

Is the script in the text label?

If not then try these:

Instead of script.parent, call upon the gui via part ex:

local 1=target.NameofGUI.NameofTextLabel:WaitForChild()


Also maybe instead of defining the local player through players, define the player through the function.

Example:

local debounce = true
local target = game.Workspace:WaitForChild("Practiceobby") --Part that player will get teleported to.

script.Parent.MouseButton1Click:Connect(function(plr)
if debounce == true then
debounce=true
script.Parent.ClickSound:Play()
plr.Character.HumanoidRootPart.CFrame = target.CFrame*CFrame.new(0,3,0)
-- Teleporting the player... but doesn't work ):
debounce = true
end
end)

0
Yes the script is inside the textbutton and I also used your example but sorry it still didn't work ZombieApocalypz3 22 — 9d
0
Edited 8 days ago

why is your debounce always set to true? You should also have a cooldown.

Shouldn't it be this:

local debounce = true
local target = game.Workspace:WaitForChild("Practiceobby")

script.Parent.MouseButton1Click:Connect(function(plr)
if debounce == true then
debounce = false     ---CHANGED THIS
script.Parent.ClickSound:Play()
plr.Character.HumanoidRootPart.CFrame = target.CFrame*CFrame.new(0,3,0)