Studio errors a "nil" value object but still modifies it

Roblox errors me “nil” passed object even tho it modifies it…

-- Client:
local Magazine = script.Parent.Parent.Mag
Event:FireServer("PlayAnimation",Animations.Reload,Magazine)
--------------------------------------------------------------------
-- Server:
ReplicatedStorage.Gun.OnServerEvent:connect(function(Player, ...)
local Args = {...}
-- code
local TheMagazine = Args[3]
TheMagazine.Transparency = 1 -- Line 56
-- code
end

image

(Not a local part)

Help?

Why did you do this?

ReplicatedStorage.Gun.OnServerEvent:connect(function(Player, ...)
local Args = {...}

You know you can do this, right?

ReplicatedStorage.Gun.OnServerEvent:connect(function(Player, someOtherArg, anotherArg, TheMagazine)

I, and many other developers, prefer the method he does. I happen to use one RemoteEvent for everything and use it like this

ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, request, ...)
    local args = {...}
    if request == "BuyItem" then
        buy(player, args[1])
    end
end)

It’s perfectly normal practice.

2 Likes

It could be that the event that errors and the event that changes the color are separate.

Try adding in a print to see how many times in total the callback runs – it might be just the first time it runs where it errors, or a time after the first.

1 Like