Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

Where is this "nil value"? Is Meteor on the last code snippet defined?

0

it is .Name and it is "BasePart", not "Part"

1 answer

✓ Accepted answer

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 :)

3 comments

0

thanks ill try it

0

umm i also need a touch event on the floor to go with it

0

That is already there! script.Parent.Touched:Connect(function()

This discussion is preserved as it was. New answers, comments, and votes are closed.