Local return an error as a nil value

I just want to keep this simple:

I have a local that gets a model, the problem is that when I try to clone that model, the script prints: Attempt to index local StoredOrb, a nil value

StoredOrb is getting an object from ServerStorage, which I don’t think why I could have this error, thanks for reading.

1 Like

Try making StoredOrb a global variable.

If you mean using _G. Then I want to say that hackers can get that value, and they can be able to get the object in the value and change it. And I’m not using a local script.

1 Like

May I see your code?
[30 characters]

Is “StoredOrb” an object in ServerStorage or?..

Are you using a server script?, otherwise that’s the problem, the server storage isn’t replicated to the client

Greetings. @Conejin_Alt has specified that he isn’t using a local script, so I’m not quite sure.

1 Like

Yes I said it.


@rokec123

local HitBox = script.Parent
local ServerStorage = game:GetService("ServerStorage")

HitBox.Touched:Connect(function(obj)
    ServerStorage:FindFirstChild("ChangingOrb"):Fire(HitBox)
end)

The other script located in ServerScriptService:

--locals here, too lazy to write them
ServerStorage.ChangingOrb.Event:Connect(function(CurrentOrb)
    CurrentOrb:Destroy()
    local StoredOrb = ServerStorage:FindFirstChild("Orb") --Error
    local ClonedOrb = StoredOrb:Clone()
end)

I just wrote the lines that are important to this discussion. And yeah, this took long to write cuz I’m in mobile

Greetings. So, have you checked if “Orb” has been found?..

Orb is set in server storage, I can see that, I think there is no logic needed to this.

If I remember correctly The first parameter of a RemoteEvent is the player.

ServerStorage.ChangingOrb.Event:Connect(function(plr, CurrentOrb)
    CurrentOrb:Destroy()
    local StoredOrb = ServerStorage:FindFirstChild("Orb") --Error
    local ClonedOrb = StoredOrb:Clone()
end)

Ah, so is there is just a singular orb?.. Or are there multiple variants?..

He’s not using remote events, it’s server-server communication

Ah, i didn’t even realize that Thank you for pointing that out ( sry missed that)

1 Like

You should have a check that makes sure StoredOrb isn’t nil, otherwise there’s no point in calling :FindFirstChild().

There is only one, 30chars…

What I’m saying is, if you’re not making sure StoredOrb isnt’t nil, it’s the same thing as if you didn’t call :FindFirstChild()

As I said, Orb is not nil, Orb is a model set in ServerStorage.

According to the error, it is.
However, I was only giving you an advice for the future.

Sorry for the misunderstandings there at the beginning but, Are CurrentOrb and Orb be any chance the same instance or is Orb within CurrentOrb ? if so you are destroying it before calling: ServerStorage:FindFirstChild("Orb")