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

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

Asked by 5 years ago

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?

0
Which line is line 105? Epuuc 74 — 5y
0
local c = game.ReplicatedStorage:FindFirstChild(“Crown”):Clone() NeutralEnergy -1 — 5y

1 answer

Log in to vote
0
Answered by
Epuuc 74
5 years ago
Edited 5 years ago
  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.
0
Oh you’re right! How can I prevent this error in the future so I can become a better scripter? NeutralEnergy -1 — 5y
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. CreatorMan2006 -2 — 5y
0
Hello, I am still getting the same error even though I made the changes, what do you think is the problem? NeutralEnergy -1 — 5y
Ad

Answer this question