When Im using MouseButton1Click its not working

Can you try to put some print statements in your script? Make sure your script is actually running.

hey, read the documentation well, stop being lazy, also copy my answers and call me disrespectful, learn to receive constructive criticism

Hey, I know you’ve spent hours on this since the people who have been there aren’t as smart as we’re saying, but do this: put the script inside the ui pay attention to me for once and try it in the studio, it doesn’t have anything to do with it, also put some impressions which will help you and another thing you must see the output well and look for that script

You aren’t providing any logics or explanations to your points. Both containers allow local script to run, so it doesn’t matter. A local script can run in StarterGui container and StarterCharacterScripts. I had attested this in studio.

1 Like

I used some “prints” and the code before and after my function is firing

Do they print anything in the output tab?

by chance I ask your game is for phones?

Yes, both before and after the function, but not in the function

It has support for phones, yes

Seems like this is a hard issue to solve, try using this script for other buttons?

You’re assuming that there’s already stuff loaded within the PlayerGui, but chances are is that it has the potential to give back nil, which is a non-existent value & you would attempting to index a variable that doesn’t exist just yet

Also, if there would be no errors within your script then you should’ve gotten none within your Output Tab as well cause indexing the PlayerGui & recieving an error back is a pretty common thing & it wouldn’t make sense if you didn’t a singular one

What you’ll have to do, is assign several WaitForChild calls starting with the PlayerGui, and considering how your script is sorted out, it’s gonna be a painful process on yielding each individual Instance

I would also consider using MouseButton1Down instead, as MouseButton1Click tends to behave strangely for some platforms

print("This is running")

local Plr = game.Players.LocalPlayer
local PlrGui = Plr:WaitForChild("PlayerGui")

print("Player GUI loaded")

local MainGui = PlrGui:WaitForChild("MainGUI")

local Main = MainGui:WaitForChild("PhoneMain")

local PhoneHUD = MainGui:WaitForChild("PhoneHUD")
local Menu = PhoneHUD:WaitForChild("Menu")
local Frame = Menu:WaitForChild("Frame")
local ImageButton = Frame:WaitForChild("ImageButton")

local Buttons = Menu:WaitForChild("Apps"):WaitForChild("Home"):WaitForChild("Apps")
local Cash = Buttons:WaitForChild("Cash")
local Button = Cash:WaitForChild("Button")

print("Everything else loaded")

Button.MouseButton1Down:Connect(function()
	warn("Clicked, should work")
end)

Although there are helpful resources that avoids this process, as you can take a look ChipioIndustries’s “WaitForPath” Post that avoids this consistent method calling

2 Likes

In that case, a MouseButtonup or something like that, I don’t know how to write it well, I don’t speak English, I use a translator

Trying this with a different button in the same phone ui did not work for me either

Wait, are you testing the script using a computer or a phone?

good answer it opened my mind but do it like this:

local Menu = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGUI").PhoneMain
local MenuButton  
local player = game.Players.Localplayer



local Buttons = Menu.Apps.Home.Apps
MenuButton =  Menu.PhoneHUD.Menu.Frame.ImageButton
Buttons.Cash.Button.MouseButton1Click:Connect(function()
	warn("HIE")
end)

so it is more optimized

Computer, In studio, also here is the full phone if this helps:
Screenshot 2023-01-27 184247

I don’t know why I put the player on, I’m sorry I’m not in the studio and I can’t test it and I don’t know if it’s okay

This compared to the original script is no way “optimized” than the other. This is literally the same thing except you assign a value to the MenuButton variable at a later time.

That still doesn’t resolve the issue that PlayerGui can in fact, return back nil depending on the User’s Platform and how fast it can perform

Also, you’re indexing the LocalPlayer after retrieving the PlayerGui which does not make sense, please make your posts as contribute & effective as possible rather than just adding more nonsense to the mix here

1 Like

Okay, maybe try inserting a local script in the Button instance with this code:

script.Parent.MouseButton1Click:Connect(function()
    print("WORKS")
end)