I added a script a normal one in a tool that makes it CanCollide false which I want the tool to go through the wall, but if I drop it, then it goes back to CanCollide to true. I tried to make a script and I know I did a terrible job but how can I fix this?
1 | local tool = script.Parent.Model |
2 |
3 | if tool.Dropped then |
4 | tool.CanCollide = true |
5 | elseif tool.PickedUp then |
6 | tool.CanCollide = false |
7 | end |
You should listen for the .AncestryChanged event of the tool. tool.Dropped and tool.PickedUp aren't properties or events of a tool. Also, tools aren't models and models don't have a CanCollide property.
01 | local players = game:GetService( 'Players' ) |
02 | local tool = script.Parent |
03 | local handle = tool.Handle |
04 |
05 | tool.AncestryChanged:Connect( function () |
06 | if players:GetPlayerFromCharacter(tool:FindFirstAncestorOfClass(model)) then -- it's a descendant of a player's character |
07 | handle.CanCollide = false |
08 | else |
09 | tool.CanCollide = true |
10 | end |
11 | end ) |