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

How do I fix this collision issue with this placement preview?

Asked by 5 years ago

Even after making sure CanCollide is disabled, this placement preview is still collidable. This happens in a localscript (so that only you can see your preview). Even after disabling CanCollide, you can still jump on it, and push zombies with it, and push yourself with it. How to fix?

local createPreview = function()
    if tower.Value == 1 then
        if preview then preview:Destroy() end
        preview = game.ReplicatedStorage.Towers.gun:Clone()
        placementregion = preview:FindFirstChild("PlacementBox")
        rangeindicator = preview:FindFirstChild("RangeIndicator")
        for i,v in pairs(preview:GetDescendants()) do
            if v:IsA("BasePart") then
                if v.Name ~= "RangeIndicator" and v.Name ~= "PlacementBox" then v.Transparency = 0.5 end
                v.BrickColor = placecolor
                v.CanCollide = false
                local mesh = v:FindFirstChild("Mesh")
                if mesh then
                    mesh.TextureId = ""
                end
            end
        end
        preview.PrimaryPart = placementregion
        preview.Parent = workspace.Towers
    end

    if tower.Value == 2 then
        if preview then preview:Destroy() end
        preview = game.ReplicatedStorage.Towers.sniper:Clone()
        placementregion = preview:FindFirstChild("PlacementBox")
        rangeindicator = preview:FindFirstChild("RangeIndicator")
        for i,v in pairs(preview:GetDescendants()) do
            if v:IsA("BasePart") then
                if v.Name ~= "RangeIndicator" and v.Name ~= "PlacementBox" then v.Transparency = 0.5 end
                v.BrickColor = placecolor
                v.CanCollide = false
                local mesh = v:FindFirstChild("Mesh")
                if mesh then
                    mesh.TextureId = ""
                end
            end
        end
        preview.PrimaryPart = placementregion
        preview.Parent = workspace.Towers
    end

    tower.Changed:Connect(function()
        if tower.Value == 1 then
            if preview then preview:Destroy() end
            preview = game.ReplicatedStorage.Towers.gun:Clone()
            placementregion = preview:FindFirstChild("PlacementBox")
            rangeindicator = preview:FindFirstChild("RangeIndicator")
            for i,v in pairs(preview:GetDescendants()) do
                if v:IsA("BasePart") then
                    if v.Name ~= "RangeIndicator" and v.Name ~= "PlacementBox" then v.Transparency = 0.5 end
                    v.BrickColor = placecolor
                    v.CanCollide = false
                    local mesh = v:FindFirstChild("Mesh")
                    if mesh then
                        mesh.TextureId = ""
                    end
                end
            end
            preview.PrimaryPart = placementregion
            preview.Parent = workspace.Towers
        end

        if tower.Value == 2 then
            if preview then preview:Destroy() end
            preview = game.ReplicatedStorage.Towers.sniper:Clone()
            placementregion = preview:FindFirstChild("PlacementBox")
            rangeindicator = preview:FindFirstChild("RangeIndicator")
            for i,v in pairs(preview:GetDescendants()) do
                if v:IsA("BasePart") then
                    if v.Name ~= "RangeIndicator" and v.Name ~= "PlacementBox" then v.Transparency = 0.5 end
                    v.BrickColor = placecolor
                    v.CanCollide = false
                    local mesh = v:FindFirstChild("Mesh")
                    if mesh then
                        mesh.TextureId = ""
                    end
                end
            end
            preview.PrimaryPart = placementregion
            preview.Parent = workspace
        end
    end)


    spawn(function()
        while preview and placementregion and rangeindicator and placing.Value == true do

            local ray = Ray.new(workspace.Camera.CFrame.Position,(mouse.Hit.Position-workspace.Camera.CFrame.Position).Unit*500)
            local ignorelist = {workspace.Enemies,workspace.Towers,player.Character,preview,workspace["Projectiles/Traps"]}
            local part,position = workspace:FindPartOnRayWithIgnoreList(ray,ignorelist,false,true)

            preview:SetPrimaryPartCFrame(CFrame.new(position) * CFrame.new(Vector3.new(0,(placementregion.Size.Y/2),0)) * prevrot)
            local torso = preview:FindFirstChild("Torso")
            cf = torso.CFrame

            for i,v in pairs(preview:GetDescendants()) do
                if v:IsA("BasePart") then
                    v.BrickColor = placecolor
                    v.CanCollide = false
                end
            end
            wait()
        end
    end)
end
0
what are u even doing, just use :GetTouchingParts() greatneil80 2647 — 5y
0
then create collision groups for each part greatneil80 2647 — 5y
0
Collision groups can only be used by the server. I specified that this is a LocalScript. Reset935681 5 — 5y
0
Late response, uh, I just realized there's a property in parts that lets you set their collision ID, so that I don't need to use the localscript to set the collision groups so... RIP? Reset935681 5 — 5y

Answer this question