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?
01 | local debounce = true |
02 | local player = game.Players.LocalPlayer -- The player |
03 | local target = game.Workspace:WaitForChild( "Practiceobby" ) --Part that player will get teleported to. |
04 |
05 | script.Parent.MouseButton 1 Click:Connect( function () |
06 | if debounce = = true then |
07 | debounce = true |
08 | script.Parent.ClickSound:Play() |
09 | player.Character.HumanoidRootPart.CFrame = target.CFrame*CFrame.new( 0 , 3 , 0 ) |
10 | -- Teleporting the player... but doesn't work ): |
11 | debounce = true |
12 | end |
13 | end ) |
Type of script is a LocalScript
More Info
game.Workspace.Part.SurfaceGui.TextButton.LocalScript
Is the script in the text label?
If not then try these:
Instead of script.parent, call upon the gui via part ex:
1 | local 1 = target.NameofGUI.NameofTextLabel:WaitForChild() |
Also maybe instead of defining the local player through players, define the player through the function.
Example:
01 | local debounce = true |
02 | local target = game.Workspace:WaitForChild( "Practiceobby" ) --Part that player will get teleported to. |
03 |
04 | script.Parent.MouseButton 1 Click:Connect( function (plr) |
05 | if debounce = = true then |
06 | debounce = true |
07 | script.Parent.ClickSound:Play() |
08 | plr.Character.HumanoidRootPart.CFrame = target.CFrame*CFrame.new( 0 , 3 , 0 ) |
09 | -- Teleporting the player... but doesn't work ): |
10 | debounce = true |
11 | end |
12 | end ) |
why is your debounce always set to true? You should also have a cooldown.
Shouldn't it be this:
01 | local debounce = true |
02 | local target = game.Workspace:WaitForChild( "Practiceobby" ) |
03 |
04 | script.Parent.MouseButton 1 Click:Connect( function (plr) |
05 | if debounce = = true then |
06 | debounce = false ---CHANGED THIS |
07 | script.Parent.ClickSound:Play() |
08 | plr.Character.HumanoidRootPart.CFrame = target.CFrame*CFrame.new( 0 , 3 , 0 ) |
09 | wait( 3 ) --ALSO ADDED A COOLDOWN |
10 | debounce = true |
11 | end |
12 | end ) |
could be why it's not working