What I want is to make it so that at line 3, the script will find the player, selects its torso, then select the torso's position. That way the script can be able to spawn in grass in the area that is near a grass spawn. However, output is saying Workspace.GrassScript:3: attempt to index a nil value. I don't know if my script is actually selecting the torso and its position, or if i'm doing something wrong. If my script looks stupid, keep in mind that I am a beginner when commenting your thoughts.

distance = 230 

avatar = game.Players:FindFirstChildOfClass("Player").Position
GrassSpawn = workspace.GrassPatchSpawnPoints:GetChildren()

for g=1, #GrassSpawn do
	gspawn = GrassSpawn[g]
end

A = avatar
B = gspawn.Position

if (A - B).magnitude <= distance then
	gClone = game.ServerStorage.GrassPatchClone:Clone()
	gClone.parent = workspace
	gClone.Position = B
	gClone.Rotation = Vector3.new(0,math.random(0,175),0)
		
else
	gspawn.transparency = 1
end

Updated Script:

distance = 230 --num value to studs "put in stud distance"

GrassSpawn = game.ServerStorage.GrassPatchClone:GetChildren()
A = workspace:WaitForChild(game.Players:FindFirstChildOfClass("Player").Name):WaitForChild("Head").Position
B = GrassSpawn.Position

while (A - B).magnitude <= distance do
	gClone = game.ServerStorage.GrassPatchClone:Clone()
	gClone.parent = workspace
	gClone.Position = B
	gClone:GetChildren().Rotation = Vector3.new(0,math.random(0,175),0)
		
end

2 comments

0

I edited my answer.

0

There is no property named transparency btw