Story game; StringValue Roadbloack

So as some have seen in my last post I am making a story game to see how it would turn out. I feel like its a nice way to get ahold of some more advanced scripting that I do not know of yet.

I made it where when you enter the first of three elevators and get a StringValue named “Elevator1”.

Does anyone know how I would destroy the StringValue out of the player when they hit the ExitButton?

When … Event happens

(function(plr)
       for _,v in pairs(plr:GetChildren()) do
              if v.Name == "Elevator1" then
                  v:Destroy()
       end)
end)

Should this be in a certain script?

in the exit script, you would call mousebutton1click:Connect(function()) and then insert the code i told you.

Alsoif its a localscript do

local plr = game.Players.LocalPlayer

If its not put it as a parameter in the function

You don’t need the extra function in the function, and it should be set as plr inseatd of player.

Also your ends are everywhere lol

I redid it and it still has the same parsing expression problem?

Could you show me the script please ?

Forgive me if its a simple mistake, im not that smart-

Move the end that’s second from last and add 2 at the end of the if statement

Like this?

the first end on the if statement still has the parsing expression problem, it just didn’t show when I took the screenshot.

Hold up. I think I got it, let me check.

1

2

Get rid of the plr in the parameter,

Didn’t solve the index nil problem, and now “plr” has a blue underline.

Again the variable needs to be changed to plr not player

What are you talking about? Im sorry but Im so confused.

What is he saying is this:

Remove the parameter “plr”, of the function, and name “plr”, the game.Players.LocalPlayer part. Also, please don’t post screenshots of code, just formate it, then i will explain better.

It seems like you don’t know how to reference the local player correctly. Here’s what you should be doing.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
script.Parent:MouseButton1Click:Connect(function()
    for _, child in pairs(player:GetChildren()) do
	    if child.Name == "Elevator1" then
		    child:Destroy()
			-- Do any other logic here
            break
		end
	end
end)