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.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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?

script.Parent.MouseButton1Click:connect(function()
local player = game.Players.LocalPlayer
0
Wait, you need it so when you press the button it teleport s a player to you? Mrmonkeyman120 48 — 3mo
0
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
1
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

workspace.CustomizationGuiPart.SurfaceGui.Hats.Afro.MouseButton1Click:Connect(function()

local Player = game.Players.LocalPlayer -- player

print(Player.Name)

end)
0
this isnt a gui in startergui this is a gui inside a part in workspace Gameplayer365247v2 729 — 3mo
0
Put I want the script to be server sided. Pooglies -4 — 3mo
0
Your reply's are horrible you don't even understand what i have said read it more carefully Prestory 1390 — 3mo
Ad
Log in to vote
0
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")
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

Answer this question