So I managed to write a script that will unanchor the part when touched but how could I make it so that if it touches "Brick", it unanchors "Brick"?
function touch()
script.Parent.Anchored = false
end
script.Parent.Touched:connect(touch)
So I managed to write a script that will unanchor the part when touched but how could I make it so that if it touches "Brick", it unanchors "Brick"?
function touch()
script.Parent.Anchored = false
end
script.Parent.Touched:connect(touch)
function touch(part)
if part:IsA("Part") then --Checks if it's a Part
script.Parent.Anchored = false
end
end
script.Parent.Touched:Connect(touch)
or:
function touch(part)
if part.Name == "Brick" then --Checks if it's a part named Brick
script.Parent.Anchored = false
end
end
script.Parent.Touched:Connect(touch)
So the parameter part is referencing on what touched the script's parent.
Hope this helps!
Well, an easier way is to used Part.Touched:Connect(function() because it's just simple and understandable.
First, let's define all the variables;
local Brick = script.Parent
Simple right? This will guarantee that Brick is script.Parent.
Now we add the event that will fire when requirements are there. so it would look like;
local Brick = script.Parent
Brick.Touched:Connect(function()
end)
and lastly, we can do what we want to do. In this case, unanchor the brick;
local Brick = script.Parent
Brick.Touched:Connect(function()
Brick.Anchored = false
end)
I'm not sure why your script isn't working but make sure this script is a **ServerScript** NOT a **LocalScript**.
If this helped then please accept answer ;)
Good luck developing!
How would I be able to specify Touched because I want it so if a part touches it, it unanchors but if a humanoid, it wont unanchor.
Then get the player's body parts, so if Hit.Parent:WaitForChild('Character').WaitForChild('Left Arm') then return end
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
How would I make "Brick" unanchored though?
Never mind! I just edited a line and now it works! Thanks a bunch!
Just make sure you're learning.