Attempt index nil? issue

I got error which is this


and after thi issue it will broke my scripts

for i, v in pairs(Players:GetChildren()) do
			if v.Character:FindFirstChild("Win") then
				v.Character.Win:Destroy()
			end

the if v.Character is line 119

please help me.

The error is indicating that the script is unable to find something called “Win” inside what should be the player’s Character.

However, there’s a chance that the player’s Character does not exist when you are trying to reference it, which means that Character would be nil , essentially making the variable reference nil.Win .

In order to resolve this, check if the Character exists/wait for it to load into the game before indexing something inside of it:

for _, player in ipairs(Players:GetPlayers()) do
    local Character = player.Character or player.CharacterAdded:Wait()
    
    if Character then
       -- Continue
    end
end

after this scripts it make my game more error.

what it make me more error.
Untitled

well as you can see v isnt a variable probably set it as the player?

i see so what will i do this i will delete the v?

You’re supposed to put your code that you originally put, like:

for _, player in ipairs(Players:GetPlayers()) do
    local Character = player.Character or player.CharacterAdded:Wait()
    
    if Character then
			if Character:FindFirstChild("Win") then
				Character.Win:Destroy()
			end
    end
end
2 Likes

I make it solution but i still chaged something so it will not give other scripts error.

1 Like