Hello! I am trying to make a tool that when a specific part touches it, it will make the CanCollide value false. I have tried putting the script in the tool, and in the part.
But, when I put the tool in StarterPack, it works. (The tool is currently in a folder in ReplicatedStorage and is given to you through a UI.
How can I make it work when it’s given to you?
(Note: I have tried printing the name of the part touching it, and when it was given to me, it didn’t print anything)
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Door" then
hit.Parent.CanCollide = false
wait(2.5)
hit.Parent.CanCollide = true
end
end)
Oh that makes more sense now. Since it is in the serverscript it probably runs only once unless you call it through event. So basically what happens:
Your server script runs at the start of your game. It looks for the tool but doesn’t find it and moves on (unless it was there from beginning, that is why it works when it is in starter pack).
When you give your tool to player through UI, serverscript can’t see it because it looked for it only in beginning. All you have to do is make an event that fires to serverscript when you give the tool so the script could “see” it.
What @Poseidon995 said makes sense. I assume you’re using a local script to clone it; the client can’t see that and therefore won’t clone the script with it. You will have to use an event to clone instead