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

How to refer to the player within the workspace in a hierarchy?

Asked by
81b 5
7 years ago
Edited 7 years ago

EDIT: I found a way to get the script to work myself, but if you have any answers you'd like to give please feel free.

I'm currently stumped on this problem. I'm trying to run a Destroy() command in my LocalScript when the player touches a block, but the LocalScript is within the player, and I don't know how to get the game to recognize the name of that player. Whenever I test my script, it keeps presenting the players is not a valid member of Workspace error ("players" is the current name I'm trying) I've also tried Characters, but that doesn't work either. I know there is a way to get this to work, but that's only if there's a function involved that can help define it, and there's no functions here. Here's my script:

local cam = workspace.CurrentCamera 

cam.FieldOfView = 120
wait (2)

local i = 120
repeat
   cam.FieldOfView = i
   wait(0.01)
   i = i - 1
until i==70

wait(0.1)
workspace.players.LocalCamScript:Destroy()

The last line, workspace.players.localCamScript:Destroy(), is where the error's coming from.

Is there a general term referring to the player I can use that the game will recognize? Or is there a different process involved?

All help appreciated, and feel free to ask questions about what I'm trying to do, if it'll help find a solution. Also point out if there's something else I'm doing wrong that's causing this error.

EDIT: I should also note that this works perfectly fine when I name it as "Player1" instead of "players" but I know that won't work outside of studio's test mode since that's referring to a specific player name. I've also tried Model, which should be the name of the player walking on the block, who literally IS a model -- but that doesn't work.

0
Are you trying to destroy the script itself? honeygold13843 136 — 7y
0
Yup. 81b 5 — 7y
0
I looked again at the destroy property and found out that when the destroy command is called, set the Parent property to nil and locks the Parent property. Since the parent in this case is the player, will this affect anything pertaining to the player that's important? 81b 5 — 7y

2 answers

Log in to vote
0
Answered by
systack 123
7 years ago
Edited 7 years ago

You want the script to destroy itself when the block is touched?

local cam = workspace.CurrentCamera 

cam.FieldOfView = 120
wait (2)

local i = 120
repeat
   cam.FieldOfView = i
   wait(0.01)
   i = i - 1
until i==70

wait(0.1)
script:Destroy()

If you want to find the player from a localscript, use

game.Players.LocalPlayer
Ad
Log in to vote
0
Answered by 7 years ago

Try doing

game.Workspace.players.LocalCamScript:Destroy()

instead of

workspace.players.LocalCamScript:Destroy()

Answer this question