Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

More Info

game.Workspace.Part.SurfaceGui.TextButton.LocalScript

0
Also you might want to change it to a regular script brodywth 97 — 3y
0
ok ZombieApocalypz3 35 — 3y
0
LocalScripts don't run in Workspace. uhi_o 417 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years 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 35 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years 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)
       wait(3) --ALSO ADDED A COOLDOWN
         debounce = true
        end
    end)

could be why it's not working

0
i think i figured it out, i just placed the local script in starter gui and changed some variables and it worked. Thanks for helping though ZombieApocalypz3 35 — 3y

Answer this question