How to get button clicked if local script not parented to button

Hi,
I’m just wondering how to make a function that runs when a player clicks the button, but in another script. I thought I knew, but the event is not firing and the function is not running

local plr = game.Players.LocalPlayer 
--make transparent
local startGui = game:GetService("StarterGui")
local shippingGui = startGui.delivered.showPath.packet
shippingGui.Visible = false
--delivered is a screen gui, show path a frame, packet an image button
startGui.delivered.showPath.packet.MouseButton1Click:Connect(function() --not triggering
	print("Connect") --not printed
end)

1 Like

You need to get the PlayerGui of the Player not the StarterGui. Try something like this:

local plr = game.Players.LocalPlayer 
--make transparent
local startGui = plr:WaitForChild("PlayerGui")
local shippingGui = startGui.delivered.showPath.packet
shippingGui.Visible = false
--delivered is a screen gui, show path a frame, packet an image button
startGui.delivered.showPath.packet.MouseButton1Click:Connect(function() --not triggering
	print("Connect") --not printed
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.