"MouseButton1Click is not a valid member of TextButton"?

Hello, recently I’ve been trying to make a simple GUI that either closes if you click the ‘play’ button and kicks you if you click ‘don’t play’.

local gui = game.StarterGui.welcome

gui.Button.MouseButton1Click:Connect(function()

gui.Frame.Visible = false

end)

gui.lolButton.MouseButton1Click:Connect(function(plr)

plr:Kick("You aren't banned, you just didn't want to play lol")

end)

Isn’t a text button supposed to have the MouseButton1Click function? I have checked that each item is parented correctly so the ‘valid member’ error doesn’t pop up.

Edit: I noticed I wrote MouseButton1Click incorrect and have fixed it, but it did not fix the script

4 Likes

I would try doing game.Players.LocalPlayer.PlayerGui.welcome

2 Likes

Its game.Players.LocalPlayer.PlayerGui though, but player gui takes a while to appear so I dont recommend.

Also doing game.StarterGui is a bad idea since it controls what will appear once the player joins or respawns and not what currently is in the screen.

2 Likes

You should be getting the instance of the UI inside of the playertoo, not the one in the StarterGui folder. This is game.Players.LocalPlayer.

3 Likes

You can use game.Players.LocalPlayer:WaitForChild(“PlayerGui”), so this isn’t an apparent issue.

2 Likes

Aside from the fact that you should be editing the object located inside of PlayerGui rather than StaterGui in this situation, you typed “MouseButtonClick1” rather than MouseButton1Click.

For future reference, you can click on the “View” tab in studio and then select the “Object Browser.” It has a list of objects with their properties & functions.

3 Likes

It will give a error even using that though, It only waits for 5 seconds. If he uses a higher cooldown for the wait for child then maybe

2 Likes

Surely the PlayerGui doesn’t take any longer than 5 seconds to lead into the client? Even if it does takes longer, just change :WaitForChild(“PlayerGui”) to :WaitForChild(“PlayerGui”, (time to wait))

2 Likes

Why don’t you just put a local script in the gui and fire a remote event to a ServerScript and kick the player from there?

2 Likes

try changing MouseButtonClick1 to MouseButton1Click

3 Likes

It says gui.Button.MouseButtonClick1:Connect(function()
change to MouseButton1Click.

2 Likes

This works, just put a RemoteEvent in replicated storage.

Local script inside of a ScreenGui:

local PlayButton = script.Parent.PlayButotn
local DontPlayButton = script.Parent.DontPlayButton
local Player = game.Players.LocalPlayer

PlayButton.MouseButton1Click:Connect(function()
	--make the frame invisible
end)

DontPlayButton.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(Player)
end)

ServerScript:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	player:Kick("You didnt wanted to play")
end)

Edit: I didn’t realize you could do it from the client.

4 Likes

This was the solution, thank you!

also learned how to use a simple remote event xddd

2 Likes

Seems like all he wants to do is kick the local player if they decide to click the “don’t play” button, which means that there’s no need for separating it between the server and client with a remote event. He can simply just kick the local player.

There’s also no need to pass “Player” as an argument - the player that fires a remote is automatically sent.

1 Like

This is false, they do the same thing and work with all platforms, for readability, you should use Activated.

1 Like

I didn’t realise this, this information on another post, I’ll edit the post, my apologies!

1 Like

You don’t use StarterGui to change a players ui. You have to use PlayerGui. The StarterGui just clones the children into PlayerGui when entering a game

1 Like