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

"Right Shoulder is not a valid member of Part"?

Asked by
soutpansa 120
7 years ago

I have a script, it clones a model to the players arm, and the model has a script inside of it to hurt other players etc. But when I reset, I get "Right Shoulder is not a valid member of Part", and the script no longer works. Any ideas on what's wrong?

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:wait()
local mouse = Player:GetMouse() 
local lastUse = 0;
Run = game:GetService("RunService")




local function onKeyDown(key) 
    local Key = key:lower()
    if key == "z" and  tick()-lastUse > 20  then 
        lastUse = tick(); 
local rarm = game.ReplicatedStorage.Hamon.RArm:Clone()
local torso = char:WaitForChild("Torso")
local RightShoulder = torso["Right Shoulder"]
                    local a = Instance.new("Sound")
                       a.SoundId = "http://www.roblox.com/asset/?id=157325701"
                       a.Parent = rarm
                       a.Volume = 2
                       a:play()
                    local char = Player.Character
                    if rarm ~= nil then
                        local rarmweld = Instance.new("Weld")
                        rarmweld.Parent = rarm
                        rarmweld.Part0 = rarmweld.Parent
                        rarmweld.Part1 = char:findFirstChild("Right Arm")
                        rarmweld.C1 = CFrame.new(0, 0, 0)
                        rarm.Parent = char
                    end

           RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 1.6)
           game:GetService("Chat"):Chat(Player.Character.Head, "Sendo Hamon Overdrive!")
           wait(20)
           RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -1.6)
           Run.Stepped:wait(0.01)










    end
end


mouse.KeyDown:connect(onKeyDown)

0
Make a function that updates the character and torso variable each time they reset. iiTylerSoul 56 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Hi, soutpansa.

To fix your problem, you need to make a function that updates your character and torso variable each time the player respawns.

You need to do this because, when the player respawns, your torso variable, which is now the player's old torso, no longer has the "RightShoulder" weld and is now just a useless part.

However, your script doesn't know that the torso variable is no longer the torso in the player's new body. This is why you need to update your torso variable to your player's new body.

You need to also update your character variable to your player's new body or you would get the player's old torso.

Here is the character updating function I personally use:

local Player = game.Players.LocalPlayer
local UserInput = game:GetService("UserInputService")

local Character
local Torso

UserInput.InputBegan:connect(function(key) --Test
    if key.KeyCode == Enum.KeyCode.Q then
        print(game.Players:GetPlayerFromCharacter(Character).Name)
    end
end)



local function loadCharacter(char)  --char is the player's character that is being updated.
    Character = char --Updates the Character variable to the player's new character.
    Torso = Character:WaitForChild("Torso") --Makes the Torso variable.
end

if Player.Character then --If the character is added to the player, run function.
    loadCharacter(Player.Character)
end

Player.CharacterAdded:connect(loadCharacter) --Each time character is added to the player, run function

The "loadCharacter" function has a paramater called char. It is updated to the player's character each time the player respawns.

In the function, we assign the Character variable to the "char" parameter. Then, we assign the Torso variable to the Character's torso.

To add my function to your code, delete all your character and torso variables.

Now, create two variables in a global scope. (I personally make them the last variables in the global scope.)

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

local lastUse = 0;

local Run = game:GetService("RunService")

local char  --Added new 
local torso --variables.

After you created your variables, make your loadCharacter function. Make sure to name your parameter something different from your global character variable.

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

local lastUse = 0;

local Run = game:GetService("RunService")

local char  --Added new 
local torso --variables.

local function loadCharacter(character) 
    char = character
    torso = char:WaitForChild("Torso")
end

Almost done. You have to put your function into action. I'm not sure why, but I always put this code at the end of my script. Feel free to mess around with the position.

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

local lastUse = 0;

local Run = game:GetService("RunService")

local char  --Added new 
local torso --variables.

--You put your code here.

local function loadCharacter(character) 
    char = character
    torso = char:WaitForChild("Torso")
end

if Player.Character then
    loadCharacter(Player.Character)
end

Player.CharacterAdded:connect(loadCharacter)

Finally, code on with your script normally. You don't have to make new character or torso variables in your Jojo Sendo Hamon function thing.

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

local lastUse = 0;

local Run = game:GetService("RunService")

local char  --Added new 
local torso --variables.

local function onKeyDown(key) 
    local Key = key:lower()

    if Key == "z" and tick()-lastUse > 20  then 
        lastUse = tick();

        local rarm = game.ReplicatedStorage.Hamon.RArm:Clone()
        local RightShoulder = torso["Right Shoulder"]

                    local a = Instance.new("Sound")
                       a.SoundId = "http://www.roblox.com/asset/?id=157325701"
                       a.Parent = rarm
                       a.Volume = 2
                       a:play()

                    if rarm ~= nil then
                        local rarmweld = Instance.new("Weld")
                        rarmweld.Parent = rarm
                        rarmweld.Part0 = rarmweld.Parent
                        rarmweld.Part1 = char:findFirstChild("Right Arm")
                        rarmweld.C1 = CFrame.new(0, 0, 0)
                        rarm.Parent = char
                    end

               RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 1.6)
               game:GetService("Chat"):Chat(char.Head, "Sendo Hamon Overdrive!")
               wait(20)
               RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -1.6)
               Run.Stepped:wait(0.01)
    end
end


mouse.KeyDown:connect(onKeyDown)

local function loadCharacter(character) 
    char = character
    torso = char:WaitForChild("Torso")
end

if Player.Character then
    loadCharacter(Player.Character)
end

Player.CharacterAdded:connect(loadCharacter)
0
If you don't understand something or there is some grammar, spelling or coding issue you can't decipher, ask me about it here. iiTylerSoul 56 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Right Shoulder is not considered a part of the Humanoid or Player.

Use something like this:

character = plr.Character
local Y = Instance.new("Weld")
                Y.Part0 = character.["Left Arm"]
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0

Answer this question