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
8 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?

01local Player = game.Players.LocalPlayer
02local char = Player.Character or Player.CharacterAdded:wait()
03local mouse = Player:GetMouse()
04local lastUse = 0;
05Run = game:GetService("RunService")
06 
07 
08 
09 
10local function onKeyDown(key)
11    local Key = key:lower()
12    if key == "z" and  tick()-lastUse > 20  then
13        lastUse = tick();
14local rarm = game.ReplicatedStorage.Hamon.RArm:Clone()
15local torso = char:WaitForChild("Torso")
View all 51 lines...
0
Make a function that updates the character and torso variable each time they reset. iiTylerSoul 56 — 8y

2 answers

Log in to vote
0
Answered by 8 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:

01local Player = game.Players.LocalPlayer
02local UserInput = game:GetService("UserInputService")
03 
04local Character
05local Torso
06 
07UserInput.InputBegan:connect(function(key) --Test
08    if key.KeyCode == Enum.KeyCode.Q then
09        print(game.Players:GetPlayerFromCharacter(Character).Name)
10    end
11end)
12 
13 
14 
15local function loadCharacter(char)  --char is the player's character that is being updated.
View all 24 lines...

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.)

1local Player = game.Players.LocalPlayer
2local mouse = Player:GetMouse()
3 
4local lastUse = 0;
5 
6local Run = game:GetService("RunService")
7 
8local char  --Added new
9local torso --variables.

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

01local Player = game.Players.LocalPlayer
02local mouse = Player:GetMouse()
03 
04local lastUse = 0;
05 
06local Run = game:GetService("RunService")
07 
08local char  --Added new
09local torso --variables.
10 
11local function loadCharacter(character)
12    char = character
13    torso = char:WaitForChild("Torso")
14end

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.

01local Player = game.Players.LocalPlayer
02local mouse = Player:GetMouse()
03 
04local lastUse = 0;
05 
06local Run = game:GetService("RunService")
07 
08local char  --Added new
09local torso --variables.
10 
11--You put your code here.
12 
13local function loadCharacter(character)
14    char = character
15    torso = char:WaitForChild("Torso")
View all 22 lines...

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.

01local Player = game.Players.LocalPlayer
02local mouse = Player:GetMouse()
03 
04local lastUse = 0;
05 
06local Run = game:GetService("RunService")
07 
08local char  --Added new
09local torso --variables.
10 
11local function onKeyDown(key)
12    local Key = key:lower()
13 
14    if Key == "z" and tick()-lastUse > 20  then
15        lastUse = tick();
View all 55 lines...
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 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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

Use something like this:

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

Answer this question