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

How to access player in regular script?

local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local Commands = {}


function Commands.FadeShop()
local FadeFrame = Instance.new('Frame',PlayerGui)
FadeFrame.Size = UDim2.new(0,10,0,10)
	
for i = 1,0,-.1 do 
wait(.1)
FadeFrame.BackgroundTransparency = i
end
	
end









return Commands

Player is a Nil Value(Error)

I am sorry this question was deleted by accident D:

3 comments

0

The question you need to answer is: Which player??

0

the player playing the game

0

There are many players playing the game... ROBLOX is multiplayer

4 answers

You can cycle through all the players in a game like below...

for i, v in pairs(game.Players:GetChildren()) do --i for index, v for reference to player
	if(v.Name == "PlayerNameHere") then
		--set-up gui or do whatever you want here
	end
end

--If you want to do it for all the players then just remove the if statement
for i, v in pairs(game.Players:GetChildren()) do --i for index, v for reference to player
	--set-up gui or do whatever you want here
end

I'm not sure if script.Parent.Parent.Parent will work, and personally I think that is more confusing. This is the ideal way to do, either do the same thing for all players, or search through the players for that particular player you want to modify things under.

local Player = script.Parent.Parent.Parent --remove or add Parents depending where your script it

mine was in StarterGui.Child.Child.Script

so script.Parent.Parent.Parent the third .Parent made it go to StarterGui.

one more .Parent would be the Player


try this

function onPlayerEntered(Player)

local PlayerGui = Player:WaitForChild('PlayerGui')

local Commands = {}

 

 

function Commands.FadeShop()

local FadeFrame = Instance.new('Frame',PlayerGui)

FadeFrame.Size = UDim2.new(0,10,0,10)

 

for i = 1,0,-.1 do

wait(.1)

FadeFrame.BackgroundTransparency = i

end

end

return Commands
game.Players.ChildAdded:connect(onPlayerEntered) 

3 comments

0

it's in the workspace

0

you'd have to move the script then or use a localscript

0

He is asking for a regular script, not a local script

--all you have to do is make it a local script and put
game.Players.LocalPlayer

9 comments

0

really bro

0

XD The best answer of them all.

0

XD The best answer of them all.

0

XD The best answer of them all.

0

XD The best answer of them all.

0

XD The best answer of them all.

0

XD The best answer of them all.

0

XD The best answer of them all.

0

Woah... Spammed ;-; How?

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