New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

How to get a player from a surface gui click?

Asked by 3 months ago

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?

local player = game.Players.LocalPlayer
Wait, you need it so when you press the button it teleport s a player to you? Mrmonkeyman120 48 — 3mo
No, I need it so when you press the button, it gives the player a hat, I have that script sorted, I just need to get the player from the click Pooglies -4 — 3mo

2 answers

Log in to vote
Answered by
Prestory 1390 Moderation Voter
3 months ago

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


local Player = game.Players.LocalPlayer -- player


this isnt a gui in startergui this is a gui inside a part in workspace Gameplayer365247v2 729 — 3mo
Put I want the script to be server sided. Pooglies -4 — 3mo
Your reply's are horrible you don't even understand what i have said read it more carefully Prestory 1390 — 3mo
Log in to vote
Answered by 3 months ago

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")

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")
local character = game.Players.LocalPlayer.Character
    character.HumanoidRootPart.CFrame = THE NAME OF THE PART HERE.Position)

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

Answer this question