You cannot detect MouseButton1Click on a GUI from a server-sided script. Instead, you will have to use something called a RemoteEvent in order to fire it from the client to the server. I have included some examples below.
-- Make this a LocalScript inside the TextButton itself.
local TextButton = script.Parent
TextButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer() -- again, it may be necessary to change this to reference to your RemoteEvent. Make sure to insert a RemoteEvent. Inserting one into ReplicatedStorage will allow this script to work without changing anything.
end)
Then, from a server-sided script, you can pick up when the event is fired and perform the things on the server.
-- Make this a regular script
-->>: Below is going to insert a sound into the character.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if not char.Head:FindFirstChild("Sound") then
local SoundID = "rbxassetid://1838058421" -- Put your SoundID here
local PlayerHead = char:WaitForChild("Head")
local sound = Instance.new("Sound")
sound.Parent = PlayerHead
sound.SoundId = SoundID
end
end)
end)
-->>: Below will detect when the event is fired and play the sound
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- change this to wherever you put your RemoteEvent. It must match the location of the one you put in the LocalScript.
local head = player.Character:FindFirstChild("Head")
head.Sound:Play()
end)