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

Arm Transparent attempt fail, why?

Asked by 10 years ago
player = game.Players.LocalPlayer

local player_arm = "Left Arm"

while true do
    wait(1)
    player.player_arm.Transparent=.5
end

if player.player_arm.Transparent==.5 then
    print('Working!!!')
end

Doesn't work, and its suppose to make your left arm transparent, WHy not working?

4 answers

Log in to vote
7
Answered by 10 years ago

Several mistakes here, but it's nothing too difficult to fix.

First of all, when you use player_arm on lines 7 and 10, the script ignores your variable and tries to look for a part named "player_arm". This is the first error. To fix this, use brackets or the FindFirstChild function.

while true do
    wait(1)
    player[player_arm].Transparent=.5 --Bracket method. Normally the name inside the brackets should be a string, but your variable is already defined as a string.
end

if player:FindFirstChild(player_arm).Transparent==.5 then --Function method. Again, the parentheses should contain a string.
    print('Working!!!')
end

Second, LocalPlayer redirects to the Player itself (the one that contains PlayerGui, Backpack, etc.), not the model that contains parts. To fix this, redirect to the player's model by using .Character.

while true do
    wait(1)
    player.Character[player_arm].Transparent=.5 --This line now redirects to the Player's Character (model)
end

Third, the property you're thinking of is called "Transparency", not "Transparent".

while true do
    wait(1)
    player.Character[player_arm].Transparency=.5 --Transparent changed to Transparency
end

Your completed script should now look like this:

player = game.Players.LocalPlayer

local player_arm = "Left Arm"

while true do
    wait(1)
    player.Character[player_arm].Transparency=.5
end

if player.Character[player_arm].Transparency==.5 then
    print('Working!!!')
end

I hope this helps! If you found my answer helpful you can upvote and accept it. If you have any questions, just ask.

0
I got ninja'd again IcyArticunoX 355 — 10y
0
Very well explained(: +1 Goulstem 8144 — 10y
0
Thank you! IcyArticunoX 355 — 10y
0
Thanks, it is very well explained too. and thanks for your effort mikeCONronald 25 — 10y
Ad
Log in to vote
4
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Well I have no idea why you tagged this as 'Camera' but to answer your question..

You're attempting to index the player for the Left Arm. The Left Arm is a child of the Character. and even if you were indexing the correct scope then you're doing it wrong. You cannot say player.player_arm.Transparent = .5, you'd need to at least use the FindFirstChild method with the player-arm variable as the arguments. And lastly, the property you need to manipulate is named Transparency, not Transparent.

And I'm not sure why you're attempting to set the transparency in a loop.. but here's the fix;

local player = game.Players.LocalPlayer
local player_arm = "Left Arm"

while wait(1) do
    player.Character:FindFirstChild(player_arm).Transparency = .5
end

if player.Character:FindFirstChild(player_arm).Transparency == .5 then
    print('Working!!!')
end

EDIT

Another way to index the Character using the variable is by player.Character[player_arm]

Log in to vote
4
Answered by 10 years ago

Identifier player_arm is only saving/identifying a string, and not an actual BasePart type instance, we can fix this by editing the code a bit, by identifying that Left Arm is in the Parent, also, when you run this script, it may error because Left Arm may not be existant at the time when the code executes, considering using the WaitForChild method, let's fix up your code;

local player = game.Players.LocalPlayer --This will identify the current Player, or, as the WIKI says, 'The Player that the LocalScript is running for'
repeat wait() until player.Character --This will repeat waiting until 'player''s Character is existant
local player_arm = player.Character:WaitForChild("Left Arm") --This will repeat waiting until 'Left Arm' is existant within the Player's Character; The 'WaitForChild' method will repeat waiting until the Child is existant within the Parent, and will return it, afterwards, the identifier 'player_arm' will return the Child

player.player_arm.Transparency = .5 --Noticed an error while editing your script, you used 'Transparent', 'Transparent' is not a property for the 'BasePart', thus will cause an error when attempted to use, considering changing to 'Transparency'? :P --This will now change the Player's Character' 'Left Arm', or identifier 'player_arm',  Transparency property to '0.5'

if player_arm and player_arm.Transparency >= 0.5 then --The 'if then end' statement will check the conditions for a block of code; This will check to see if 'Left Arm' is existant, and will check 'player_arm' if it's Transparency property is Greater or Equal to 0.5
print("Half transparent! :D") --This will print in the Output; this will print if the condition for the 'if then end' statement were/are met
end --This ends the block of code for the 'if' statement

Hope this helped!

Log in to vote
2
Answered by
Destrings 406 Moderation Voter
10 years ago

That's not how it works

player.player_arm is actually player["player_arm"]

player = game.Players.LocalPlayer

while true do
    wait(1)
    player["Left Arm"].Transparent=.5
end

if player["Left Arm"].Transparent==.5 then
    print('Working!!!')
end

0
player["player_arm"] wouldn't work, because 'player_arm' is not a valid member of the character, much less the player. You'd have to do player.Character[player_arm] if anything.. and the variable is already a string so no need for tostring(: Goulstem 8144 — 10y
0
Um wat? I only was saying that player.player_arm is a syntactic sugar for player["player_arm"] nothing more. Destrings 406 — 10y

Answer this question