You where correct with the function,
So to continue on that we need to clone the gui into the players Playergui
01 | function FindClosestPlayer() |
04 | for i,v in pairs (game.Players:GetPlayers()) do |
05 | if v.Character ~ = nil then |
06 | if (v.Character.Torso.Position - script.Parent.Position).magnitude < dist then |
07 | dist = (v.Character.Torso.Position - script.Parent.Position).magnitude |
18 | for i,v in pairs (script:GetChildren()) do |
19 | if v:IsA( "ScreenGui" ) then |
21 | pl = FindClosestPlayer() |
22 | if game.Players:FindFirstChild(pl) ~ = nil then |
23 | if game.Players:FindFirstChild(pl).PlayerGui:FindFirstChild(v.Name) = = nil then |
24 | cl.Parent = game.Players:FindFirstChild(pl).PlayerGui |
25 | game.Players:FindFirstChild(pl).Character.Humanoid.WalkSpeed = 0 |
32 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
Gui must be in the script, and script in the part.
Hope this helps