Functions with Gui

hey! so i have a bit of a problem. i want to run a function when i click a gui, but i want that function to only apply to the person that clicked the gui. i know how to do it with touching parts: (function(hit) & hit.Parent

but how would i do that with gui click instead of part touching.

any help is appreciated!! <33

just do this

local gui = --whatever ur button is

gui.MouseButton1Up:Connect(function()
-- ur function here
end)

Click detector on a gui? how do i do that?

My bad, I thought it you wanted for player to click on a part. For clicking on Gui, you can use MouseButton1Click and make sure it’s a GuiButton.

1 Like

There’s no ClickDetector for gui, instead use a TextButton or ImageButton

how would i make the function only work for the player that clicked the button. like how when touching a part you can use “function(hit) hit.Parent”
how would i do that with a gui?

1 Like

Just add a Gui inside of StarterGui and write the script inside LocalScript in the Gui, LocalScripts work for individual players

sry i explained it rly bad. for my script i am making it so when you click a gui button, your character wears an accessory. the script is

button = script.Parent
BlondeHair = game.ReplicatedStorage.NCBlonde

button.MouseButton1Click:Connect(function()
BlondeHair.Parent = …
end)

i just dont know what to put at the “…” to make the parent of the hair the person that clicked the gui.

button = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
BlondeHair = game.ReplicatedStorage.NCBlonde

button.MouseButton1Click:Connect(function()
BlondeHair.Parent = character
end)

plus i think this wouldn’t work as it’s a client side script

Try firing a remote event instead.
You can find tutorials on RemoteEvents on the hub and YouTube as well.