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

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

Asked by 6 years ago

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()
0
Most likely because 'sword.Parent.Parent' is referring to workspace rather than the character model. Double check the directory of the script. ScriptGuider 5640 — 6y
0
I'd prefer using Player = game...blah blah blah. instead of script.parent Zafirua 1348 — 6y
0
But then how do I know who the player that is using this sword is? SweetNoodleSoup 14 — 6y

1 answer

Log in to vote
0
Answered by
PlaasBoer 275 Moderation Voter
6 years ago

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.

0
Thanks. I already found another solution, but this solution could also work so I'll accept the answer. SweetNoodleSoup 14 — 6y
0
okay thanks too. PlaasBoer 275 — 6y
Ad

Answer this question