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

Access LocalPlayer on Workspace?

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

1 comment

6 answers

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

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.

2 comments

0

Accessories are in workspace, not in Players.

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.)

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

1 comment

0

If it's solved, consider accepting one answer so nobody else has help you further.

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.

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

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