What I want my code to do is that if these 2 certain parts are destroyed (nil I believe), then the owner of the Factory will receive 10 Player Points. But it doesn't give me an output error and doesn't give me the Points (Even if I press Play on the website). Can someone help me?
if script.Parent.Factory.Grader1 == nil and script.Parent.Factory.Grader2 == nil then --Grader1 and Grader2 are the bricks that have to be destroyed to get the Player Point game:GetService("PointsService"):AwardPoints(script.Parent.Factory.OwnerName.Value, 10) --Gives the Factory Owner 10 Player Points end --No output, No Points... Why?
Do not check if a child property is nil: This does not happen, and it results in an error for attempting to access a member which does not exist. E.g., accessing workspace.ThisBrickIsntaThing
triggers an error since there is no such thing to access.
We can safely check the existence of a part using FindFirstChild
.
Your condition should read,
if (not script.Parent.Factory:FindFirstChild("Grader1")) and (not script.Parent.Factory:FindFirstChild("Grader2")) then
We use FindFirstChild
in this way in the sense of "does this child exist".