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

Why does it say LaserGate1 is not a valid member of Workspace?

I have made a simple script to remove something from the game when i touch a block but when i touch the block it tells me LaserGate1 is not a valid member of Workspace even though LaserGate1 is under workspace

function onTouched(hit)
	game.Workspace.LaserGate1 = nil
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

Hello. Your method in doing this isnt exactly corrent. What your probably trying to do is remove, or destroy LaserGate1. To accomplish this, do the following:

function onTouched(hit)
	game.Workspace.LaserGate1:Destroy()
end
script.Parent.Touched:Connect(onTouched)

You will see that I have replaced line 2. You were on the right track in trying to set the object to nil because what destroy does, is set the objects PARENT to nil, you were just missing the .Parent. Besides that point, :Destoy() was implemented specifically for this, thus its what I suggest you use. I hope I was able to help! ~mc3334

4 comments

0

Thanks i'm new to scripting

0

Happy to help :)

0

Why do you add the parameter "hit"?

0

you dont have to people just like to do that

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