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

Help Script Errors?

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

2 comments

0

What does the output say?

0

I don't know it does not say anything.

3 answers

✓ Accepted answer

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)

1 comment

0

If this doesn't help, Sorry. Maybe try to give some more info on what task you want to accomplish?

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

2 comments

0

If the localplayer is nil, then how will it even find the character? Also, don't use 'repeat wait()' but try using ROBLOX's built-in method. 'local player = game.Players.LocalPlayer or game.Players.LocalPlayer:wait()'

0

The LocalPlayer will never be nil. It is a property of the Players service. As for the repeat loop, I just prefer the style. If I remember correctly, the wait() method can only be used on events. 

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.

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