Getting the player that clicked a textbutton on a surfacegui

I am making a computer monitor that can spawn disasters inside a map. I like the scrollinggui look, but I can’t figure out how to make it so when you click the textbutton it returns the player. This isn’t something that can be ran on the client since the disasters it can spawn affects everyone. When I treat it like a normal clickdetector it returns nil instead of the player. Is there any way around this, or do I have to use clickdetectors and settle for buttons?

why not just check for clicks on the client and fire a RemoteEvent to the server when the button is clicked

2 Likes

This is totally do-able with UI instead of physical parts and buttons. From the context you’ve given me I can’t quite figure out if you’re meaning a surfacegui or a screengui.

Let me know which you’re using (either the UI is on a part’s surface, or on the user’s screen)!

It’s a surfacegui on a physical part’s surface., and I’d prefer it to be this way.

Alright, do you have a script already written that’s not working, or are you asking how you’d do it?

Going back to the first thing said here, having a remote event send what button was clicked to another server script somewhere will work. If you don’t know what those are, I recommend using this as help.

I tried doing it similar to how I’d handle when a button in a GUI was clicked. I don’t get why this can’t be a normal script, as clickdetectors accomplish the same thing. on the server’s end, and I assumed you would be able to handle a click event on a surfacegui on the server’s end as well. Here’s the code, which returns an error that I attempted to index nil with player, meaning for some reason the clicking is being detected, but I can’t get the player who clicked. It’s not a big deal if I have to use remote events, but I suspect there might be a way to accomplish what I want without using one.

	print(player)
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId,722349705) then
		if debounce == false then
			debounce = true
			local Disaster = game.ServerStorage.Disasters.VolcanoDisaster:Clone()
			Disaster.Parent = workspace
			for i,v in pairs(Disaster:GetDescendants()) do
				if v:IsA("Script") then
					v.Enabled = true
				end
			end
			Disaster.Lava.Music:Play()
			cooldowntimer = 60
			while wait(1) and cooldowntimer > 30 do
				cooldowntimer -= 1
			end
			Disaster:Destroy()
			while wait(1) and cooldowntimer > 0 do
				cooldowntimer -= 1
			end
			debounce = false
		end
	else
		MarketplaceService:PromptGamePassPurchase(player,722349705)
	end
	debounce = false
end)

As odd as it seems after looking into it there is no way to get surfaceguis to detect clicks in a similar way as click detectors do, which is a bit counterintuitive and inconvenient but not a huge deal. After implementing remoteevents into my code it is now functioning.

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