Does Mouse Button One Click work the same way ClickDetector Does

I Have scripted A ClickDetector so whenever a player clicks on a part In Takes away there currency then it gives them and ability this is the script It Just A Normal script Btw that I Used

script.Parent.ClickDetector.MouseClick:Connect(function(player)

if player.leaderstats.Points.Value >= 1000 then

player.leaderstats.Points.Value = player.leaderstats.Points.Value - 1000

– I gave the player a special ability here
end
end)

but If I Have A Text Button With A Script not a local script Inside and I typed This script…

script.Parent.MouseButton1Click:Connect(function(player)
if player.leaderstats.Points.Value >= 1000 then

player.leaderstats.Points.Value = player.leaderstats.Points.Value - 1000

– I gave the player a special ability here
end
end)

1 Like

MouseButton1Click doesn’t return any arguments. Only ClickDetectors do.

Instead, you could try using RemoteEvents to do this.

1 Like

Or you could use this tricky way of getting players straight from the server-sided script

-- Script
local Button = script.Parent.TextButton

Button.MouseButton1Click:Connect(function()
	local Player = script:FindFirstAncestorOfClass("Player") -- Get player that click the gui button
	if Player then
		print(Player.Name) -- Player that click the button
	end
end)

and if you want your point function to be implemented on the gui button then

-- Script
local Button = script.Parent.TextButton

Button.MouseButton1Click:Connect(function()
	local Player = script:FindFirstAncestorOfClass("Player")
	if Player and Player.leaderstats.Points.Value >= 1000 then
		Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - 1000
	end
end)

It is pretty similar

1 Like

Oh yeah, forgot about :FindFirstAncestorOfClass. That would work as well.

1 Like