Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Would this work??

Asked by 10 years ago

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?
0
1. You need an ID not a name. 2. You need enough points from the game. fireboltofdeath 635 — 10y
0
Oh yeah!! thanks! Last time I checked I have like 5000 points remaining... fahmisack123 385 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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".

Ad

Answer this question