Detecting text button click from server

I’ve been working on a shop system, and I need to detect if a player clicked a text button from the server. I don’t want to use a remote event as that would be unprotected, and unreliable. Is there anyway to detect if the player has clicked a text button from the server?

1 Like

I’m pretty sure it’s the exact same as a local script for this

textbutton.MouseButton1Click:Connect(function()
end)
1 Like

texbutton.Activated works too i think

Here’s some examples about from client to server

local script (Must be inside the button)

local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent", 2)
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer()
end)

server script (Must be in ServerScriptService)

local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Parent = game.ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(Player)
	print(Player.name.." is firing from client to server!")
	-- Code here:
end)

You might just have to use an event, however, use it in the way below to make it more secure. You see, if you use :FireServer() in a localscript and then OnServerEvent:Connect(function(), the first thing in that function(), like “player” is automatically the person who fired the remote. And if you were to check if the player has enough money to buy something from the shop on the server, that would be secure instead of checking if the player has enough money to buy something from the shop on the client as they can easily edit the price there with a scripteditor.

  1. Make a remoteevent called ClickedEvent.
  2. Make a localscript inside of the text button.
-- CODE FOR THE LOCAL SCRIPT
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ClickedEvent:FireServer()
end)
-- CODE FOR THE SERVER SCRIPT
game.ReplicatedStorage.ClickedEvent.OnServerEvent:Connect(function(player)
if player:FindFirstChild("leaderstats").Cash.Value >= 300 then -- if you do this on the client, that would be very much not secure
print("player has enough money to buy this")
else return;
end
end)
3 Likes

Didn’t think about that, thank you!

1 Like