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

attempt to call method Destroy (a nil value) ?

Asked by
FdPros 2
5 years ago

so basically i'm trying to make this script where their base is destroyed when they leave so bases dont clutter and stuff but testing this on a 2 player local server doesnt work and gives said error in the title.

I tried putting it as

game.Workspace.name:Destroy() 

but the same thing happens. I have checked and the name of the model I'm trying to destroy corresponds to the code. Maybe I'm missing something here? This script is on a normal script inside the workspace also filteringenabled is enabled. Must I fire to a client or something?

game.Players.PlayerRemoving:connect(function(player)
local name = player.Name.."Base"
local Thing = game.Workspace.name
print(name)
Thing:Destroy()

1 answer

Log in to vote
0
Answered by
ozzyDrive 670 Moderation Voter
5 years ago

The issue is in your syntax. game.Workspace.name is syntactic sugar to game["Workspace"]["name"]. See the issue? It is first looking for a property named "name" in the Workspace service, then for a child named "name".

You can, however, use the square bracket syntax with the 'name' variable to index player.Name.."Base" from game.Workspace: game.Workspace[name].

0
wow thanks that worked. FdPros 2 — 5y
Ad

Answer this question