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

Why is this while loop not working ?

3 answers

✓ Accepted answer

There is a way to keep a players parts CanCollide = false, it's not that complex. To do this, you want to used Stepped & a Changed event .

Changed is just use to keep the head cancollide false as a safety or whatever.

local lplayer = game.Players.LocalPlayer
repeat wait() until lplayer.Character.Head -- Make sure the body part exists, along with character
local Head = lplayer.Character.Head
local RS = game:GetService("RunService") -- You can ROBLOX wiki about this server, it has what we want, Stepped

RS.Stepped:connect(function() -- Fires every frame in ROBLOX 
	Head.CanCollide = false
end)
	
Head.Changed:connect(function(Property)
	if Property == "CanCollide" then
		Head.CanCollide = false
	end
end)

I think I commented all the info about it you need but you can Comment on this Answer if you're confused with something, otherwise accept the answer & thanks

local lplayer = game.Players.LocalPlayer
local Head = lplayer.Character.Head --Player is called before Character spawns, which creates an error.


while wait() do
    Head.CanCollide = false 
end


local lplayer = game.Players.LocalPlayer
local character = lplayer.Character
if not character or not character.Parent then
    character = lplayer.CharacterAdded:wait()
end --Add a wait for the character
local Head = character.Head

while wait() do 
    Head.CanCollide = false  --CanCollide will be set to false, however it won't actually fall through other parts.
--[[If you wish to kill the player use: ]] Head:Destroy()
end


1 comment

0

The start of your script will error anyhow without a loop to wait on the player. Use: repeat wait(1/30) until game.Players.LocalPlayer.Character at the top

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