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 8 years ago
local lplayer = game.Players.LocalPlayer

local Head = lplayer.Character.Head


while wait() do
    Head.CanCollide = false
end

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 8 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.

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

Ad
Log in to vote
0
Answered by 8 years ago
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


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 — 8y
Log in to vote
0
Answered by 8 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