wait(10) x=script.Parent[""..script.Parent.Parent.Parent.OwnerName.Value.."'s WarClone"]:clone() if game.kServerStorage[""..script.Parent.Parent.Parent.OwnerName.Value.."'s Clones"] == nil then h = Instance.new("Model") h.Parent = game.kServerStorage h.Name = ""..script.Parent.Parent.Parent.OwnerName.Value.."'s Clones" x.Parent = game.kServerStorage[""..script.Parent.Parent.Parent.OwnerName.Value.."'s Clones"] else x.Parent = game.kServerStorage[""..script.Parent.Parent.Parent.OwnerName.Value.."'s Clones"] end
kServerStorage is the ServerStorage just renamed...
I cant manage to make it to work, becuase when this script runs, the part that it check for being nil IS nil, how do I check if it is 'there', because whenever I check if it is 'there' it says in the output 'error stuffs... this thingy doesn't exist!'
So how do I check if it exists? I thought it was something like:
if game.kServerStorage[""..script.Parent.Parent.Parent.OwnerName.Value.."'s Clones"] == nil
By the way, the problem is with this part ^
Please help, thanks!
If try something like
if workspace.Part == nil then
... that won't work. Instead of getting nil
, an error will happen ("no such property 'Part' in Workspace") and it won't even get to checking your if
. So we can't use .
(or equivalently []
) to check if an object exists.
Instead, you can use :FindFirstChild
, which just returns nil
if the thing doesn't exist:
if workspace:FindFirstChild("Part") == nil then
It's fairly idiomatic in Lua to use drop == nil
or ~= nil
when it's superfluous. To see if something is not nil, you would use not
:
if not workspace:FindFirstChild("Part") then
You can read that as "if I don't find 'Part' in workspace", or "if 'Part' doesn't exist in workspace".
I would really recommend not using the "Name's Clones"
format, since it's so much more complicated than necessary. Instead, I would suggest having a "Clones" folder in the ServerStorage and referencing ServerStorage.Clone[name]
.
I would also highly recommend script.Parent.Parent.Parent
to a variable instead of repeating it all over the place. Possibly saving script.Parent.Parent.Parent.OwnerValue
to a variable, too.