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

attempt to call method Destroy (a nil value) ?

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

✓ Accepted answer

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].

1 comment

0

wow thanks that worked.

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