Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to index nil with 'Humanoid'?

I used this code to make the underwater effect but it printed out: 09:28:23.834 - Players.david73754.PlayerScripts.Water.CameraInWaterFX:82: attempt to index nil with 'Humanoid'


	if Water ~= nil then
		FisheyeEffectAlpha = FisheyeEffectAlpha + deltaTime / FisheyeEffectCycleDuration
		FisheyeEffectAlpha = FisheyeEffectAlpha - math.floor(FisheyeEffectAlpha)
humCamOffset = humCamOffset + Vector3.new(math.sin(tick() * 3) * 0.2, math.sin(tick() * 3.21) * 0.2, math.sin(tick() * 3.73) * 0.2)+ Vector3.new(math.sin(tick() * 3) * 0.2, math.sin(tick() * 3.21) * 0.2, math.sin(tick() * 3.73) * 0.2)
		local camoffs = humCamOffset + Vector3.new(math.sin(tick() * 3) * 0.2, math.sin(tick() * 3.21) * 0.2, math.sin(tick() * 3.73) * 0.2)+ Vector3.new(math.sin(tick() * 3) * 0.2, math.sin(tick() * 3.21) * 0.2, math.sin(tick() * 3.73) * 0.2)
				player.Humanoid.CameraOffset = camoffs
	end
end)

I used this code to make the underwater effect, it didn't work.

2 comments

0

This looks like some obfuscated stuff. pls clean ur code

0

how do i clean my code?

1 answer

✓ Accepted answer

This is because you are accessing the Humanoid before it is being created. Make sure you make the Humanoid's camera offset changed.

2 comments

0

good call, but player does not have a humanoid. the character does. should be player.Character:WaitForChild("Humanoid")

0

after that,it gives me attempt to index nil with 'Character'

This discussion is preserved as it was. New answers, comments, and votes are closed.