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

Is there a way to make players cancollide false without them falling through the ground?

Asked by
JSAcela 25
8 years ago

Trying to make a game and this is bugging me.

0
maybe set the players cancollide to false but insert a BodyPositon to make the player "float" on the ground level Gwolflover 80 — 8y

2 answers

Log in to vote
-1
Answered by 8 years ago

Add the following to a localscript and move it to StarterPlayerScripts in StarterPlayer. This should work unless you have something blocking it.

local charRegistry = {}

local function onCharacterAdded(char)
    local reg = {}

    local function registerChild(obj)
        if obj:IsA("BasePart") then
            reg[obj] = obj.Name
        end
    end

    for _,v in pairs(char:GetChildren()) do
        registerChild(v)
    end

    char.ChildAdded:connect(registerChild)
    charRegistry[char] = reg
end

local function onPlayerAdded(player)
    if player ~= game.Players.LocalPlayer then
        if player.Character then
            onCharacterAdded(player.Character)
        end
        player.CharacterAdded:connect(onCharacterAdded)
    end
end

for _,v in pairs(game.Players:GetPlayers()) do
    onPlayerAdded(v)
end

game.Players.PlayerAdded:connect(onPlayerAdded)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local rs = game:GetService("RunService")
local removeList

local function update()
    for char,reg in pairs(charRegistry) do
        if char:IsDescendantOf(game) then
            local torso = char:FindFirstChild("Torso")
            if torso and torso.CanCollide then
                -- Rename all the parts to BREAK.
                for part in pairs(reg) do
                    part.Name = "BREAK"
                end
                -- Immediately switch back, and turn off collision.
                for part,name in pairs(reg) do
                    part.Name = name
                    part.CanCollide = false
                end
            end
        else
            if not removeList then
                removeList = {}
            end
            removeList[char] = true
        end
    end
    if removeList then
        for char in pairs(removeList) do
            charRegistry[char] = nil
        end
        removeList = nil
    end
end

rs.RenderStepped:connect(update)
0
Wow thanks! JSAcela 25 — 7y
Ad
Log in to vote
0
Answered by 8 years ago

You can simply set the player's collidable parts to false, just make sure you don't mess with the humanoid rootpart, because that can start messing things up. It would be easier to answer if you showed the script.

Answer this question