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

how do you make a cancollide body hotkey script?

basically, I never figured this out. I want my R button to turn my character and hats cancollide=false and when I click it again It turns back to cancollide= true. is there a way to do that?

1 answer

In a Local Script:

player = game.Players.LocalPlayer -- Returns the player
character = player.Character or player.CharacterAdded:wait() -- Receives the character
mouse = player:GetMouse() -- Returns the player's mouse/keyboard

can_collide = true -- Setting a boolean for CanCollide

mouse.KeyDown:connect(function(key) -- KeyDown activates when a key is pressed on the keyboard
	if key == "R" then -- If the key is R
		if can_collide == true then -- If the value is true
			can_collide = false
		elseif can_collide == false then -- Vice versa
			can_collide = true
		end
		for i,v in pairs(character:GetChildren()) do -- Checking all the children of character
			if v:IsA("Part") then -- If the child is a part
				v.CanCollide = can_collide -- Set the value of CanCollide to the value we set earlier
			end
		end
	end
end)

Note: This code is untested, so please be considerate.

2 comments

0

It isn't working, but the script looks like it could work. There may be an error or something...idk.

0

I would like to say that this would work, but it won't. Sadly, roblox restricts certain parts of your character from having cancollide off (torso, head), which makes it EXTREMELY hard to make a non-collidable body. Sorry dude. :(

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