Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why do I keep getting "Character is not a valid member of workspace?"

I have a script for a sword that I am making. When I click play, the game is stopped and I am given the message, "Character is not a valid member of workspace." Please help me fix the problem and understand what I should do. Here is my script: (the 5th line is highlighted in red.)

local sword = script.Parent
local handle = sword:WaitForChild("Handle")
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local player = sword.Parent.Parent
local character = player.Character or player.CharacterAdded:wait()

3 comments

0

Most likely because 'sword.Parent.Parent' is referring to workspace rather than the character model. Double check the directory of the script.

0

I'd prefer using Player = game...blah blah blah. instead of script.parent

0

But then how do I know who the player that is using this sword is?

1 answer

✓ Accepted answer

It is because you have the tool in Workspace so once the game load sword.Parent.Parent is Worskpace.So charater is not a property of workspace

What I suggest you do is disable the script by clicking the disabled property or add this code.

This must be under sword variable.

sword.Disabled = true

What you then can do is you give someone the tool you set Disabled back false . What disable does it won't run the code inside the script.

2 comments

0

Thanks. I already found another solution, but this solution could also work so I'll accept the answer.

0

okay thanks too.

This discussion is preserved as it was. New answers, comments, and votes are closed.