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

ServerScriptService.Script:105: attempt to index a nil value?

Hello

I am making a script where the admins can summon maps into a work space. There seems to be only one problem. ServerScriptService.Script:105: attempt to index a nil value

Here is the code

elseif msg:lower()=="!open crown" and workspace:findFirstChild('CurrentSim') == nil then wait(1) local c = game.ReplicatedStorage:FindFirstChild("Crown"):Clone() c.Parent = game.Workspace c.Name = 'Current Sim' c:MakeJoints()

So 'currentsim' basically checks if a map is already there so the user can't generate another when one is open.

When I type out !open crown I get the error message shown before. Why does it say that? I put the maps in replicated storage and script in serverscriptservice so the maps exist.

For some reason the game thinks it doesn't exist and I am attempting to index c which is a nil value?

2 comments

0

Which line is line 105?

0

local c = game.ReplicatedStorage:FindFirstChild(“Crown”):Clone()

1 answer

  1. You're checking if there's a nil value, and if there is, it could error, so that's not the best way of doing that. Use this method instead:

if not game.Workspace:FindFirstChild("CurrentSim") then

  1. Another thing is that you're setting the name to "Current Sim" when it's checking for CurrentSim, which will return false.

3 comments

0

Oh you’re right! How can I prevent this error in the future so I can become a better scripter?

0

When you're checking if something can be nil, don't do "== nil", instead put "not" before the check. Same if you want to check if something's false, however it will not error.

0

Hello, I am still getting the same error even though I made the changes, what do you think is the problem?

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