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

Button GUI is not detecting clicks?

I made a GUI and put a local script in it, which is supposed to teleport the player when it clicks on it, however, the button isn't detecting clicks. Please can you tell me what I have done wrong, thanks in advance.

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local deployScreen = playerGui.DeployScreen
local target = game.Workspace.TeleportPart

script.Parent.MouseButton1Click:Connect(function()
		print("Working")
		player.Character.HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0)
		deployScreen.Enabled = false
end)

Thanks in advance :).

7 comments

0

Have you checked for errors prior to the mouseclick event?

0

There weren't any errors before mouseclick.

0

I mean the only thing I could think of is the script itself may accidentally be disabled or you are literally not using A textbutton.

0

What is the class for script.Parent

0

What do you mean by that?

0

Did you make sure script.parent is the button?

0

Yeah script.Parent is the button

2 answers

You are attempting to use a local script to affect objects in the workspace. Instead, use your local script to trigger a remote event located in Replicated Storage in order to teleport the player with a script located in Server Script Storage.

Insert a RemoteEvent named teleportTrigger in Replicated Storage

Here is an example of your local script:

local Players = game:GetService(“Players”)
local player = Players.LocalPlayer

local RepStorage = game:GetService(“ReplicatedStorage”)
local trigger = RepStorage:FindFirstChild(“teleportTrigger”)

—I don’t know where your button and gui instances are located so this is my best guess.
script.Parent.MouseButton1Click:connect(function()
    print(“Working...”)
    trigger:FireServer()
    script.Parent.Parent:Destroy()
end)

Here is the script which is located in Server Script Storage:

local RepStorage = game:GetService(“Replicated Storage”)
local trigger = RepStorage:FindFirstChild(“teleportTrigger”)

local target = game.Workspace:WaitForChild(“teleportPart”)

trigger.OnServerEvent:connect(function(player)
    game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0)
end)

This should work make sure you put the right codes in the right scripts. I also wrote this all on my phone(took me a while) so I hope I helped.

1 comment

0

for some reason MouseButton1Click doesnt return the player, U have to fire the player directly and access the player from the script

Do not use a local script because it will be harder to manipulate objects in workspace.

	game.players.playerAdded:Connect(function(playertogetgui)
		local playerGui = player:WaitForChild("PlayerGui")
		local deployScreen = playerGui.DeployScreen
		local target = game.Workspace.TeleportPart

end
	script.Parent.MouseButton1Up:Connect(function(player)
	        print("Working")
	        player.Character.HumanoidRootPart.Position = target.Postion + Vector3.new(0,3,0)
	        deployScreen.Enabled = false
	end)

Put this in ServerScriptService. Note: I'm using Vector3 because I'm terrible at CFrame

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