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

Button GUI is not detecting clicks?

Asked by 4 years ago

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.

01local player = game.Players.LocalPlayer
02local playerGui = player:WaitForChild("PlayerGui")
03local deployScreen = playerGui.DeployScreen
04local target = game.Workspace.TeleportPart
05 
06script.Parent.MouseButton1Click:Connect(function()
07        print("Working")
08        player.Character.HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0)
09        deployScreen.Enabled = false
10end)

Thanks in advance :).

0
Have you checked for errors prior to the mouseclick event? Foxbodys 0 — 4y
0
There weren't any errors before mouseclick. pinkcust2vids 2 — 4y
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. Foxbodys 0 — 4y
0
What is the class for script.Parent moo1210 587 — 4y
View all comments (3 more)
0
What do you mean by that? pinkcust2vids 2 — 4y
0
Did you make sure script.parent is the button? LazokkYT 117 — 4y
0
Yeah script.Parent is the button pinkcust2vids 2 — 4y

2 answers

Log in to vote
0
Answered by
RGRage 45
4 years ago

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:

01local Players = game:GetService(“Players”)
02local player = Players.LocalPlayer
03 
04local RepStorage = game:GetService(“ReplicatedStorage”)
05local trigger = RepStorage:FindFirstChild(“teleportTrigger”)
06 
07—I don’t know where your button and gui instances are located so this is my best guess.
08script.Parent.MouseButton1Click:connect(function()
09    print(“Working...”)
10    trigger:FireServer()
11    script.Parent.Parent:Destroy()
12end)

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

1local RepStorage = game:GetService(“Replicated Storage”)
2local trigger = RepStorage:FindFirstChild(“teleportTrigger”)
3 
4local target = game.Workspace:WaitForChild(“teleportPart”)
5 
6trigger.OnServerEvent:connect(function(player)
7    game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0)
8end)

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.

0
for some reason MouseButton1Click doesnt return the player, U have to fire the player directly and access the player from the script TNTIsLyfe 152 — 4y
Ad
Log in to vote
0
Answered by
emervise 123
4 years ago

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

01    game.players.playerAdded:Connect(function(playertogetgui)
02        local playerGui = player:WaitForChild("PlayerGui")
03        local deployScreen = playerGui.DeployScreen
04        local target = game.Workspace.TeleportPart
05 
06end
07    script.Parent.MouseButton1Up:Connect(function(player)
08            print("Working")
09            player.Character.HumanoidRootPart.Position = target.Postion + Vector3.new(0,3,0)
10            deployScreen.Enabled = false
11    end)

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

Answer this question