Part in Model always returning nil

Hello! So recently I have started making a game which has fake hands in it. When I run the game, the hands are cloned from ServerStorage to the Workspace. From there, they go to the LocalPlayer. The reason for this is because I want to set the NetworkOwner to the Client for the model (There is a separate ServerScript doing this). Now, in my script, after the hands are cloned to the localplayer, I want to set the velocity for a part inside of the model (Called GrabSphere). For some reason, it is not detecting the part in the model and it returns nil. I already checked in the explorer and the part is in there. Anyone have any ideas?

the variable “Player” is defined by “Players.LocalPlayer”
the variable “Players” is defined by "game:GetService(“Players”)

script (LocalScript inside StarterPlayerScripts. This is not the entire script.):

output (highlighted):
Annotation 2020-07-27 112206

Don’t hesitate if you need more of the script or output!

1 Like

I think local scripts can’t run PlayerAdded and CharacterAdded Events.

1 Like

okay. So what would I do to replace it?

(I really don’t know this will work)
You could do some thing like this

function detecthands(Character)
   -- Put the whole script inside.
end

They can run it, I’ve used it sometimes in my local scripts.

I made sure the hands are in the LocalCharacter before the Velocity change is ran. Maybe this is happening because the script is in “StarterPlayerScripts”?

Actually, you can put your script in “StarterCharacterScripts” and it’ll appear direclty inside of the player’s Character.

okay. Let me try this real quick.

Oh, FindFirstChild can return nil and it won’t throw any error. Try doing ;

local LeftGrabSphere = LeftHand:FindFirstChild("GrabSphere")
local RightGrabSphere = RightHand:FindFirstChild("GrabSphere")

if LeftGrabSphere and RightGrabSphere ~= nil then
   print("GrabSpheres Detected")
end

It shouldn’t print anything. And then, if it doesn’t print anything, try switching FindFirstChild to WaitForChild.

1 Like

okay. Ill try that. Thank you.

Still nothing. Could this be happening because I have the model’s PrimaryPart set as GrabSphere?

Also, can you give me more context for

1 Like

yes i did try switching to WaitForChild.

The model’s primary part is the GrabSphere:
Annotation 2020-07-27 1122061

Annotation 2020-07-27 1122062

(this is the same for the right hand too)

Oh then, you can do :

local LeftGrabSphere = LeftHand.PrimaryPart
local RightGrabSphere = RightHand.PrimaryPart

Also, are you cloning and parenting those hands into the player character?

1 Like

Yes they are being cloned into the LocalCharacter.

The code is getting stuck on the snippet you gave me.

It thinks it should be looking for an instance named “PrimaryPart”.
It returns with the message: “PrimaryPart is not a valid member of MeshPart” which I think is weird because I do not have any meshes in my game right now.

Also, im sorry for taking up your time with this. I am working a sandbox VR game and your help is very appreciated.

Also, can you print those four variables and show me the output? (LeftHands, RightHands, LeftGrabHands, RightGrabHands)

1 Like

Sorry, but what do you mean as “print the variables”?

oh wait… i know that! lol nvmd

hold on one sec…

After the "print("Hands and Grabsp etc…) do :

print(LeftHand, RightHand, LeftGrabSphere, RightGrabSphere)
1 Like

yup there it is:
Annotation 2020-07-27 1122063

Annotation 2020-07-27 1122064

I dont get it though. If i look at my character model in the workspace in Testing, I can see the Spheres inside of the hands

I guess i could try clone the Spheres and putting them into the hands with another script

So, the problem is that LeftGrabd and RightGrab are nils, that’s it. I could probably help you fixing it but I’d need more context about how ur cloning the spheres.

1 Like