local function OnClicked() game.Workspace.Particle:Clone().Parent = click.Parent.HumanoidRootPart end script.Parent.MouseButton1Click:connect(OnClicked)
SurfaceGuis can be a bit tricky - and i'll explain why.
You're probably used to parenting the SurfaceGui to your object, and working from there. This is a common misconception because Gui objects are meant to run on the client.
In order to have you gui on the client you need to keep it in StarterGui, and set the Adornee
property. This property is basically where the gui is going to show up.
And now that the gui is on the client, you can simply index game.Players.LocalPlayer
from a LocalScript to access the player.
local click = game.Players.LocalPlayer --This is the client local adorn = workspace.Part --This is the object the gui will be on script.Parent.Parent.Adornee = adorn; local function OnClicked() game.Workspace.Particle:Clone().Parent = click.Character.HumanoidRootPart end script.Parent.MouseButton1Click:connect(OnClicked)
First, you can't just click a Surface Gui, Add a button into the surface Gui.
after all of that make sure the button is on the part visible so you can click it for later on.
Now your code will be edited;
local button = script.Parent button.MouseButton1Down:connect(function(Clicked) local clone = game.Workspace:WaitForChild("Particle"):Clone() clone.Parent = Clicked.Parent:WaitForChild("HumanoidRootPart") end)
Put this code in a local script in the button, button should be in Surface Gui
If helped, please Upvote and accept answer, if you have any other questions please comment down below. If doesn't work explain errors and so on.