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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
mc3334 649 Moderation Voter
4 years ago

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

0
Thanks i'm new to scripting Averted_Vision 177 — 4y
0
Happy to help :) mc3334 649 — 4y
0
Why do you add the parameter "hit"? AndriusTheGreat 140 — 4y
0
you dont have to people just like to do that Vortex_Vasne 89 — 4y
Ad

Answer this question