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

i was trying to make something unanchor and it said (a nil value) what do i do?

Asked by 5 years ago
local function UnAnchor()
 for _, i in pairs(script.Parent:GetChildren()) do
  if i:IsA("Part") then
   i.Anchored = false
  end
 end
end
UnAnchor()?
part = script.Parent

part.Touched:connect(function(unanchor)
 print (Meteor.name.."was touched by player" 

)end)

thats all my code

0
Where is this "nil value"? Is Meteor on the last code snippet defined? User#19524 175 — 5y
0
it is .Name and it is "BasePart", not "Part" theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You are calling a function inside itself...

do this..

local function UnAnchor()
    for _, v in pairs(script.Parent:GetChildren()) do
        if v.ClassName == "Part" then
            v.Anchored = false
        end
    end
end

script.Parent.Touched:Connect(function()
    print("Meteor was touched by player")
    UnAnchor()
end)

There were a couple of errors in your script

  1. you are calling a function within itself
  2. you have a "?" after callign your function
  3. you spelled unanchor wrong when using it in the touched event..
  4. your parenthesis on the last line was merged with end) meaning it would error

What I did... i made a loop in script.Parent:GetChildren() and made its anchor false when the player touches its parents brick

If this works for you, upvote and click accept please :)

0
thanks ill try it ihatehackers321123 9 — 5y
0
umm i also need a touch event on the floor to go with it ihatehackers321123 9 — 5y
0
That is already there! script.Parent.Touched:Connect(function() greatneil80 2647 — 5y
Ad

Answer this question