Attempt to index local "OldMic" a nil value?

Okay so, I’ve been having this problem that has been driving me crazy. So I’m trying to figure out this bug but I cannot. Also, I’ve only been scripting for about 3 weeks. The code and error is below. VV

image

image

It just means there’s no tool in the player’s backpack, so OldMic is nil. When you try to call Destroy() on it, since it doesn’t exist, it throws an error. You just need to check if the old microphone exists before destroying it:

if OldMic then
    OldMic:Destroy()
end
2 Likes

So this error means that there are no tools existing in your players inventory at the time of code execution. A simple fix would be to throw an if statement in there like what @ChipioIndustries said.

Okay, thanks! Just have 1 more bug now. image I’ve tried to do “game:GetService(“Players”).LocalPlayer” but same error comes up.

It seems you’re defining player twice, game.Players.LocalPlayer only works on client. Just use the plr you defined for what you want to do.

EDIT: It seem’s that you don’t even need this line of code, might aswell remove it

1 Like

game.Players.LocalPlayer is only for localscripts.

Your event is already giving you plr as an argument, so you don’t need to use local Player = game.Players.LocalPlayer anyway.

Just use plr when you need to reference Player.