I don't know why this does not work. Its inside a local script inside a gui, And its just part of a script.
local PlayersService = game.Players local Character = PlayersService.localPlayer.Character local items2 = Character:GetChildren() for i,j in pairs(items2) do if j.ClassName == 'Hat' then Clone7 = j:Clone() Clone7.Handle.Transparency = .5 end end
I'm not 100% sure what you want to accomplish. Although, here are some things to try...
This is inside a GUI so just make it so when you click the gui, it starts. You'll use MouseButton1Click
, if this is not what you want, then try what I've wrote bellow.
Currently, you are not setting a parent to the cloned hat. You will not have the transparent part anywhere because of this. You will need your script to look like this when you set it to a parent.
local PlayersService = game.Players local Character = PlayersService.localPlayer.Character local items2 = Character:GetChildren() for i,j in pairs(items2) do if j.ClassName == 'Hat' then Clone7 = j:Clone() Clone7.Parent = game.Workspace -- You can change the Hierarchy to where you like. Clone7.Handle.Transparency = .5 end end
You may also try a whole new Variable instead of Clone7, I don't think this will do anything. Sometimes adding a wait() for Localscript will help (In start of code)
Alpha is right that you don't set a parent. That is a problem. However, there's more.
Always watch your spelling and capitalization. Your problem is writinglocalPlayer
on line 2. This property should be spelled LocalPlayer
.
Also, making a variable for the Players service is pretty unnecessary, especially since you only use it once and your variable name is actually longer than just typing game.Players
And what if the character is nil when the code runs? That would cause problems. We must wait for the character to load before defining the variable.
local player = game.Players.LocalPlayer repeat wait() until plr.Character--Equivalent to plr.Character ~= nil local character = player.Character
Close! I see what you're attempting to do. Let me first correct you on somethings. If you're trying to access the PlayerService, use the GetService method. Also be careful about binding variables to the localplayer, as there is a chance it hasn't loaded yet. Also, use the :IsA when checking the Instance Type
playerService = game:GetService("Players") plr = playerService.LocalPlayer or playerService.LocalPlayer:wait() chr =plr.Character or plr.Character:wait() for _,v in pairs(chr:GetChildren()) do if v:IsA("Hat") then v.Transparency = .5 end end
I'm not positive on what you are trying to do, but this is my best guess.