I have a part in the workspace and then a surface gui in that part, and in that surface gui a frame, and in that frame a button, I have this script going so far but dont know how to get the player using this server sided script?
script.Parent.MouseButton1Click:connect(function() local player = game.Players.LocalPlayer
You should insert a local script in StarterGui which is the more efficient way to do this and inside the local script you can place this code
workspace.CustomizationGuiPart.SurfaceGui.Hats.Afro.MouseButton1Click:Connect(function() local Player = game.Players.LocalPlayer -- player print(Player.Name) end)
Ok, so guessing you want to teleport the player to that part? This is how. Your gonna need to have a RemoteEvent in ReplicatedStorage. This is assuming you have Filtering Enabled turned on. Next lets just name the RemoteEvent...TeleportEvent. Ok, so we need a local script inside of the button. We need to fire the event and send it to the server script.
local ReplictedStorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.TeleportEvent:FireServer()
Ok, so that will be the LocalScript for now..Now for the ServerScript. We need to use "On server event" to find when that RemoteEvent has been fired. We will also put the teleport script inside of it.
local ReplicatedStorage = game:GetService("ReplicatedStorage") game.ReplicatedStorage.TeleportEvent.OnServerEvent:Connect(function(player) local character = game.Players.LocalPlayer.Character character.HumanoidRootPart.CFrame = CFrame.new(workspace.PUT THE NAME OF THE PART HERE.Position) end)
Ok, so this will teleport you when you click the surface gui. Not really sure what you really want, but I think this is pretty close! Tell me if it doesn't work, and I can fix it. I just did this on top of my head, lol. Enjoy your day! -Mrmonkeyman