Scripts in tools don't work unless it's in StarterPack

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)

2 Likes

Can you provide the script? Specifically the part that changes the CanCollide value to false?

2 Likes
script.Parent.Touched:Connect(function(hit)
	if hit.Name == "Door" then
		hit.CanCollide = false
		wait(2.5)
		hit.CanCollide = true
	end
end)

That is my script

1 Like

Is this in a server script or a local script? Note that local scripts won’t run in workspace

2 Likes

That script is in a serverscript

1 Like

Perhaps try this? Not sure if it’ll work though

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)
2 Likes

This doesn’t seem to work for me, it works in starterpack but not when it’s given to me

1 Like

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.

2 Likes

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

2 Likes

@Poseidon995 @lluckvy Okay! I’ll try it and I will tell you my results when I am done :slight_smile:

1 Like

Hooray! It works! Thank you so much for your help!

2 Likes