Surface Buttons aren't working?

Hello. I have TextButtons on these parts that when clicked are supposed to fire the server for an event. They are not doing this. The buttons aren’t even being registered as being clicked.

The buttons very clearly do their little color change effect when I click them, so I know that I’m clicking them, but button.Activated never runs.

Code:

local players = game:GetService("Players")
local events = game.ReplicatedStorage.Events
local model = script.Parent.Parent.Parent.Parent
local player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
	print("oh")
	local itemName = model.Name
	events.PressedWeapon:FireServer(itemName)
end)

“oh” is never printed into the console.

Use a local script and put the localscript inside starterplayerscripts

I’m not certain if this is just a bug, but .Activated doesn’t work (the best) for surface buttons.

Try .MouseButton1Down

This also does not work. I tried that first acutally.

That seems tedious. I would have to define every surface button I would want the player to press, which is upwards of 40.

Or use collection service to connect it easy

Also, I don’t think you’re supposed to be calling for the GetService function within a local script, normally that is for a Server Script.

The playerScript idea does work, and I may resort to that + collection service, but it isn’t tackling the heart of the issue as to why surface buttons are not detecting in their own scripts. Do local scripts not run in workspace parts?

Ah true, it isn’t used anyways so I will delete it.

You cannot put textbuttons on workspace surface guis, as it is not in startergui so there would be no way to click it.
Just put the surface gui in startergui and set the adornee to part, so that you can click it.

3 Likes

That is the ideal solution that will work properly, just tested it and it works perfectly fine.

Got it to work now, thanks a bunch. Weird that surfaceGuis work like that, but I guess that’s the way things are.

Unrelated, but I wish I could thumb this up tenfold. Saved me some stress.

2 Likes