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

Detecting part collisions with CanCollide false, can someone explain why it doesn't work?

Sorry for the bad scripting. I started 4 days ago.

game.ReplicatedStorage.KickTGR.OnServerEvent:Connect(function()
	script.Parent.Touched:Connect(function(hitskid)
		local player = game.Players:GetPlayerFromCharacter(hitskid.Parent)
		local id = 
		local ts = game:GetService("TeleportService")
		if player.Name ~= game.Players.LocalPlayer.Name then
			ts:Teleport(id, player)
		else
			return
		end
	end)
end)

The script itself works fine, but when I try turning off CanCollide it stops working.

It should work fine, but it doesn't.

Note: The part is stored in ServerStorage and then it is moved to your character, through a script.

https://developer.roblox.com/en-us/articles/detecting-collisions

-- CryntoxB

4 comments

0

.Touched should always work with or without collisions enabled, maybe try welding the part to the character?

0

If you are not welding it, when it's CanCollide = true, it falls on the ground but not in the void, while when it's CanCollide = false it just falls into the void ignoring all collisions and destroys itself and the script inside, that's why you don't put scripts randomly in parts. Try using welds then as shadowstorm said

0

It has a weld btw

0

wait, actually the part is 1 x 1 x 2 studs and is place directly in the arm and then welded to the arm. is that bad?

1 answer

It looks to me that you are trying to declare a variable named id and give it no value. If that's the case, then remove the = as a variable without a value doesn't need to be set to a value. If that is not what you are trying to do, then keep in mind a variable can't be set to local.

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