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

Raycasting doesn't work with filtering enabled?

Asked by 6 years ago

My building system needs raycasting and it works fine in studio but not in game, in server it detects very weird things like a union where it should say part and other weird things. Here is the script, it's a local script inside the tool (inside replicated storage). My destroy tool has the same problem

Placement

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()
Debounce = false
pressed = false
cancelled = false
canPress = false

tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        print("Mouse pressed!")

        if Debounce == false then

            Debounce = true     

            local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 30)
            local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

            PreviewPart = script.Parent.Wooden_Floor:Clone()
            PreviewPart.Name = "Preview part"
            PreviewPart.Transparency = 0.5
            PreviewPart.Anchored = true
            PreviewPart.CanCollide = false
            PreviewPart.Position = position + Vector3.new(0, 0.375, 0)--  + Vector3.new(0,part.Size.Y/2,0)
            PreviewPart.Parent = workspace

            customBuild = Instance.new("Part")
            customBuild.Transparency = 1
            customBuild.Anchored = true
            customBuild.CanCollide = false
            customBuild.Name = "CustomBuild"
            customBuild.Parent = PreviewPart

            wait(1)

            canPress = true 
        end
    end)
end)

while wait() do
    if Debounce == true then

            Mouse.Button1Down:connect(function()
                if canPress == true then
                    pressed = true
                end
            end)
            Mouse.Button2Down:connect(function()
                if canPress == true then
                    cancelled = true
                end
            end)

        if cancelled == true then
            Debounce = false
            cancelled = false
            pressed = false
            canPress = false
            for i,v in pairs(workspace:GetChildren()) do
                if v.Name == "Preview part" then
                    v:Destroy()
                end
            end
            print(cancelled)
        elseif pressed == true then
            Debounce = false
            cancelled = false
            pressed = false
            canPress = false
            for i,v in pairs(workspace:GetChildren()) do
                if v.Name == "Preview part" then
                    v.Transparency = 0
                    v.Name = "Floor"
                    v.CanCollide = true
                end
            end
        end
        if PreviewPart ~= nil then
            local list = {player.Character,PreviewPart}
            local Player = game.Players:GetPlayers()
            local mouse = player:GetMouse()
            local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 30)
            local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {player.Character,PreviewPart}, false, true)
            PreviewPart.Position = position --+ Vector3.new(0, 0.375, 0)
        end
    end
end

Destroy

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()
Debounce = false
pressed = false
cancelled = false
canPress = false

tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        print("Mouse pressed!")

        if Debounce == false then

            local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 30)
            local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

            if part then
                print(part)
                if part:FindFirstChild("CustomBuild") then
                    part:Destroy()
                end
            end
        end
    end)
end)

Filtering is enabled

2
You're not using filtering enabled right. your entire placement system is client sided, which means every part created will also be client sided only. RubenKan 3615 — 6y
0
^ Like Ruben said this is completely client, you aren't going to be able to use LocalPlayer on a server script Vulkarin 581 — 6y
0
Do I need to use a serverscript? User#20388 0 — 6y

Answer this question