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

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

More Info

game.Workspace.Part.SurfaceGui.TextButton.LocalScript

3 comments

0

Also you might want to change it to a regular script

0

ok

0

LocalScripts don't run in Workspace.

2 answers

✓ Accepted answer

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)

1 comment

0

Yes the script is inside the textbutton and I also used your example but sorry it still didn't work

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

1 comment

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

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