i want to make it so that the player goes through a grass field without much lag, But it doesn't work, as it cannot understand global 'avatar' at line 10, a nil value. What do?

distance = 200

avatar = game.Players:FindFirstChildOfClass("Player")
grass = workspace.GrassField:GetChildren()

for g=1, #grass do
	grasspatch = grass[g]
end

if (avatar.character.Torso.Position - grass.Position).magnitude <= distance then
	grasspatch.transparency = 0
else
	grasspatch.transparency = 1
end

2 comments

0

I'm pretty sure just changing the transparency of a brick won't help with lag...

0

Yeah, changing the transparency does not because the physics engine still has to process it. Maybe delete the grass instead.