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

Touched script not firing or CanCollide not working?

I thought this was a good script but for some reason they dont let you go through

h1 = game.Workspace.Kingdom.Hidden1
h2 = game.Workspace.Kingdom.Hidden2

script.Parent.Touched:connect(function()
	h1.CanCollide = false
	h2.CanCollide = false
end)

1 comment

0

Are the parts single parts or models? Also i'm not sure if this is some sort of button, but this will fire when the part that the script is inside of it touched. It's also recommended to change those variables to local variables.

2 answers

✓ Accepted answer

It would be best to provide more information as to your intention when asking a question. Assuming that you want the event to fire when a player touches the block, then you would have to make sure that it has a humanoid, as the Touched event fires whenever anything touches it. Also these have to be parts. If you're wanting to turn all the parts inside to a CanCollide then use a for loop.

local h1 = game.Workspace:WaitForChild('Kingdom'):WaitForChild('Hidden1') --I would recommend adding WaitForChild to these as it will wait for the Hidden1to load
local h2 = game.Workspace:WaitForChild('Kingdom'):WaitForChild('Hidden2')

script.Parent.Touched:connect(function(hit)	
    if hit.Parent:FindFirstChild('Humanoid')
	    h1.CanCollide = false
	    h2.CanCollide = false
    end
end)

3 comments

0

I know why it is not working it is in a local script... is there anyway to fire it inside of a local script

0

it should work in a local script

0

It finally worked thanks!

Add a regular script into a Kingdom then put this

Part.Touched:connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")
	if H then
		script.Parent.CanCollide = false --false or true can work--
	end
end)

Or if you want it to open for few second do

Part.Touched:connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")
	if H then
		script.Parent.CanCollide = false
		wait(5)
		script.Parent.CanCollide = true
	end
end)

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