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

This ontouch script isn't working cancollide won't change?

script.Parent.Touched:connect(function(hit)
	game.Workspace.Blocker1.CanCollide = true
end)

really easy right? but the block's cancollide does not work it doesn't allow it to be collided with

CanCollide is already false i want it to be true though

4 answers

✓ Accepted answer
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
   		game.Workspace.Blocker1.CanCollide = true
	end
end)

Its good to use FindFirstChild because script.Parent can be touched by anything and that can really mess things up!

You're setting CanCollide to Truewhen you're supposed to make it False.

script.Parent.Touched:connect(function()
    game.Workspace.Blocker1.CanCollide = false
end)

1 comment

0

but when it's false you can't touch it i want you to be able to touch it

True is the default value of Cancollide. If you want to go through it, then you want to set it to false.

This might help:

local Blocker = workspace:WaitForChild("Blocker1")

Blocker.Touched:Connect(function(Touch) -- If the part is touched, it will connect a function to it.
	local Humanoid = Touch.Parent:FindFirstChild("Humanoid") -- This looks for a humanoid.
	if Humanoid ~= nil then - If there is a humanoid, do this:
		local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent) -- Looks for a player
		if Player ~= nil then -- If a player is found, it will set the parts' CanCollide property to false.
			Blocker.CanCollide = false
		end
	end
end)

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