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

How to fix my script that makes tool CanCollide false when picked up but true when dropped?

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?

local tool = script.Parent.Model

if tool.Dropped then
	tool.CanCollide = true
elseif tool.PickedUp then
	tool.CanCollide = false
end

1 answer

✓ Accepted answer

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.

local players = game:GetService('Players')
local tool = script.Parent
local handle = tool.Handle

tool.AncestryChanged:Connect(function()
    if players:GetPlayerFromCharacter(tool:FindFirstAncestorOfClass(model)) then -- it's a descendant of a player's character
        handle.CanCollide = false
    else
        tool.CanCollide = true
    end
end)

1 comment

0

In the 6th line, the part (model)) is underlined red, could that be an error? Also should I use local script or a script

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