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 3 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.

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

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

2 answers

Log in to vote
0
Answered by
RGRage 45
3 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:

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.

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 — 3y
Ad
Log in to vote
0
Answered by
emervise 123
3 years ago

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

Answer this question