Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I use game.Players.LocalPlayer (in gui)?

Asked by 4 years ago
Edited 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

So i'm making a game, and it requires a GUI to get your data from a folder in serverstorage.

Here is my code: (script in a gui which is in a screengui which is in startergui)

+=-THIS QUESTION HAS ALREADY BEEN SOLVED+=-

u gotta use a localscript (i'm dumb)

wait(0.5) print("hi") local Players = game:GetService("Players") print("hi") local player = Players.LocalPlayer

-- this is the line that gives an error message --

local playername = player.Name

-- this is the line that gives an error message --

print("lonley") while true do print("hiasdwasd") wait() local oxygen = game:GetService("ServerStorage"):WaitForChild("Playerinfo")[playername]:WaitForChild("oxygen") local bar = script.Parent print(playername) oxygen.Changed:Connect(function() bar.Size = UDim2.new((oxygen/100), 0, 0, 15) end)

end

Here is the error message displayed

Players.CHEESEPIZZAPARTYTIME.PlayerGui.ScreenGui.Oxygenindicator.Oxygenbar.Script:6: attempt to index nil with 'Name'

Can someone please tell me why it doesn't work?

0
Is this is a script or a LocalScript? Make it a LocalScript if not. Rinpix 639 — 4y
0
Guys im an idiot after a bit of research I have deduced that you have to use a localscript CHEESEPIZZAPARTYTIME 5 — 4y
0
add (solved) to the title so it marks as solved. Mayk728 855 — 4y

Answer this question