Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this while loop not working ?

Asked by 9 years ago
1local lplayer = game.Players.LocalPlayer
2 
3local Head = lplayer.Character.Head
4 
5 
6while wait() do
7    Head.CanCollide = false
8end

Even infinitely looping the cancollide = false

It still doesn't change to false, any ways of making the CanCollide of it permanently false?

3 answers

Log in to vote
0
Answered by 9 years ago

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.

01local lplayer = game.Players.LocalPlayer
02repeat wait() until lplayer.Character.Head -- Make sure the body part exists, along with character
03local Head = lplayer.Character.Head
04local RS = game:GetService("RunService") -- You can ROBLOX wiki about this server, it has what we want, Stepped
05 
06RS.Stepped:connect(function() -- Fires every frame in ROBLOX
07    Head.CanCollide = false
08end)
09 
10Head.Changed:connect(function(Property)
11    if Property == "CanCollide" then
12        Head.CanCollide = false
13    end
14end)

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

Ad
Log in to vote
0
Answered by 9 years ago
1local lplayer = game.Players.LocalPlayer
2local Head = lplayer.Character.Head --Player is called before Character spawns, which creates an error.
3 
4 
5while wait() do
6    Head.CanCollide = false
7end
01local lplayer = game.Players.LocalPlayer
02local character = lplayer.Character
03if not character or not character.Parent then
04    character = lplayer.CharacterAdded:wait()
05end --Add a wait for the character
06local Head = character.Head
07 
08while wait() do
09    Head.CanCollide = false  --CanCollide will be set to false, however it won't actually fall through other parts.
10--[[If you wish to kill the player use: ]] Head:Destroy()
11end
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 Legoman654 100 — 9y
Log in to vote
0
Answered by 9 years ago

This is due to the humanoid always ensuring that the head, torso, and humanoidrootpart always set cancollide to true. I haven't seen the script but see if there is a method here in CloneTrooper's anti player colliding script that can help removing collisions when touching with other parts:

https://www.roblox.com/Anti-Player-Collision-Script-item?id=316438239

Answer this question