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

Help Script Errors?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
0
What does the output say? Tempestatem 884 — 9y
0
I don't know it does not say anything. Anthony9960 210 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

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)

0
If this doesn't help, Sorry. Maybe try to give some more info on what task you want to accomplish? alphawolvess 1784 — 9y
Ad
Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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
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()' DigitalVeer 1473 — 9y
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.  Perci1 4988 — 9y
Log in to vote
0
Answered by 9 years ago

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.

Answer this question