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
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)
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