Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can i acess Local Player using a script? [FOR SURFACE GUI]

I'm working with SurfaceGUIs and i have to use a script for the button function, and that means i'd need to find a way to acess a local player using a script.

SCRIPT:

repeat wait() until game.Players.LocalPlayer ~= nil

local Player = game:GetService("Players").LocalPlayer

--\PLAYER VALUES/--

local CORE = Player.PlayerGui:WaitForChild("Core")

local Values = CORE:WaitForChild("Values")

local PaymentValue = Values:WaitForChild("PaymentValue")
local PaymentTime = Values:WaitForChild("PaymentTime")
local Employeed = Values:WaitForChild("Employeed")

--\TABEL VALUES/--

local Tabel = script.Parent.Parent

local TabelValues = Tabel:WaitForChild("Values")


local ShiftTime = TabelValues:WaitForChild("ShiftTime")
local Payment = TabelValues:WaitForChild("Payment")


script.Parent.MouseButton1Down:Connect(function()
	if Employeed.Value == false then
		Employeed.Value = true
		PaymentTime = ShiftTime
		PaymentValue = Payment
	end
end)

I can explain the code in-case you wanna help.

3 comments

0

You should handle button clicking using a local script and any stat you want to change in a server script. Use a remote event to communicate to the server for that.

0

No, localplayer is never ever accessible through normal server scripts, only local scripts.

0

how about keep trying script.Parent or script.Parent.Parent and printing til you find the player

1 answer

Although you can't use LocalPlayer in server scripts, many events pass it as a parameter. For example, PlayerAdded's only parameter is the player who joined the game.

game:GetService("Players").PlayerAdded:Connect(function(player)
	print(player.Name)
end)

1 comment

1

Thanks, i already solved it

This discussion is preserved as it was. New answers, comments, and votes are closed.