Mousebutton1click doesnt work as I want

mousebutton1click doesnt work as I want

  1. make the function work

  2. **I cant make it work

3.trying prints and google

"local script"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local re = ReplicatedStorage.BookFlight

for i, button in pairs(script.Parent:GetChildren()) do

	if button:IsA("TextButton") then

		button.MouseButton1Click:Connect(function()
			re:FireServer()
		end)
	end
end

image

2 Likes

Is this the full script, or is there more?

All of it." Full char limiiit"

What is the remote event in ServerStorage supposed to do?

İt should get the player name. But even the local script doesnt get the mouseclick

Try this change to your script. I added a print statement inside of the mouse click function, and it prints.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local re = ReplicatedStorage.BookFlight

local button = script.Parent.TextButton

if button:IsA("TextButton") then

	button.MouseButton1Click:Connect(function()
		re:FireServer()
		print("Button Clicked")
	end)
end

You will have to change this line to properly mention your text button:

local button = script.Parent.TextButton

I also noticed that you are trying to get the players name once the button is clicked. Are you trying to get the players name in the output, or somewhere else?

Yes! Im trying to get the players name on the output

No sign of life :(((((((( “charli mi t”

change the print statement to this:

print(Player.Name)

I understand that but it doesnt get the textbutton that Im clicking

Is the local script in the screenshot the local script you are using?

Yes! Im using that local script in the ss (I got delayed because of devforum sorry for late responding

I’m also assuming that you want to detect when the button named 1 is pressed, correct?

If that is the case, then change the local button line to:

local button = script.Parent[1]

it should work now i guess

--local script 


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local re = ReplicatedStorage:WaitForChild("BookFlight")

local button = script.Parent.TextButton

button.MouseButton1Click:Connect(function()
	re:FireServer()
	print("Button Clicked")
end)

--server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local re = ReplicatedStorage:WaitForChild("BookFlight")

re.OnServerEvent:Connect(function(player)
      -- do something
end)

İts not the thing I want to make because I have 165 total text buttons and in in the script I tried should work with all the buttons.

oh i see but you are using a surface gui?

Can you explain further what you want the script to do?