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

Access LocalPlayer on Workspace?

Asked by 4 years ago

Is it possible to access the Player on workspace in order to set trasparency for an Accessory? Example:

for _, v in pairs(workspace:WaitForChild(game.Players.LocalPlayer.Name)) do
    if v:IsA("Accessory") then
        v.Transparency = 0.5
    end
end

game.Players.LocalPlayer.Name not work: Player is not a valid member of DataModel

6 answers

Log in to vote
1
Answered by 4 years ago

This will not work because LocalPlayer is only accessible by local scripts. I assume you want this to happen when someone joins? If so I have forged a script below

Make sure you put this in a server/regular script. If there are any errors tell me.

game.Player.PlayerAdded:Connect(function(plr)
local char = plr.Character
for _, v in pairs(char:GetChildren()) do
if v:IsA("Acessory") then
v.Handle.Transparency = 0.5
end
end

Ad
Log in to vote
0
Answered by 4 years ago

You can't access LocalPlayer in Workspace. That's your problem.

local players = game:GetService("Players")


for _, player in pairs(Players:GetPlayers()) do
---- then you could check if the player has certain accessory or whatever you're trying to do
   end
end

Hope this works.

0
Accessories are in workspace, not in Players. Marko97_IT 2 — 4y
0
I don't know what you are trying to do so that part is on you, but that's how to get the player(unless you are trying to get character look at the post below.) Auxatier 59 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Problem solved:

local plr = game.Players.LocalPlayer.Name
for _, v in pairs(workspace[plr]:GetChildren()) do
    if v:IsA("Accessory") then
        v.Handle.Transparency = 0.5
    end
end
0
If it's solved, consider accepting one answer so nobody else has help you further. Auxatier 59 — 4y
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

To be able to access LocalPlayers. You will need to have a local script. If you don't you cant access a localplayer from a server script.

Log in to vote
0
Answered by 4 years ago

LocalPlayer is only accessible from LocalScripts in ReplicatedFirst, PlayerGui, or the player's backpack. See this page for more info: https://developer.roblox.com/en-us/api-reference/property/Players/LocalPlayer

Log in to vote
0
Answered by 4 years ago

-- I assume you have put this in a script type other than localscript, -- You can only Access LocalPlayer from a LocalScript.

Answer this question