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

Raycast still triggers through walls?

Asked by
Foxxive 10
3 years ago
Edited 3 years ago

Hello, Ironically, I got help on this just a few minutes ago and it worked but the static GUI still triggers through walls.

here is my code:

local camera = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()

local p = game.Players.LocalPlayer

local c = p.Character or p.CharacterAdded:Wait()


local VisCheck = function(Obj)
    local raycastParams = RaycastParams.new()
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
    raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
    raycastParams.IgnoreWater = true
    local raycastResult = workspace:Raycast(camera.CFrame.Position, CFrame.new(camera.CFrame.Position,Obj.Position).LookVector*5000, raycastParams)
    if raycastResult ~= nil then
        if raycastResult.Instance:IsDescendantOf(Obj.Parent) then
            if Obj.Parent.Humanoid.Health > 0 then
                return true
            end
        else
            return false
        end
    end
    return false
end

local StartUITrack = function(Obj)
    local worldPos = Obj.Position
    local pos, isOnScreen = camera:WorldToScreenPoint(worldPos)
    local fixedposx = pos.x
    local fixedposy = pos.y
    local IsInLib,num = false, nil

    if isOnScreen then
        if VisCheck(Obj)== true then
            return true
        end
    else 

    end

    return false
end







while wait() do

    local mag;

    local range = game.Lighting.FogEnd - 2;

    local cansee = true

    local DummyHead = workspace.Slenderman["Meshes/torso (3)"]

    coroutine.wrap(function()
        while wait() do
            mag = (c.Torso.Position - DummyHead.Position).magnitude;
        end
    end)()

    local WG = workspace.Slenderman

    coroutine.wrap(function()
        while wait() do
            local Position, CanSee = camera:WorldToScreenPoint(workspace.Slenderman["Meshes/torso (3)"].Position)
            if CanSee and mag <= range and cansee then 

                local StaticMain = script.Parent.StaticGUI
                local Static1 = StaticMain.Static1
                local StaticSound = script.StaticSound

                StaticSound.Playing = true
                StaticSound.Looped = true

                StaticSound.Volume = 1 /mag * 2

                StaticMain.Enabled = true
                Static1.Visible = true
                Static1.ImageTransparency = 0.50 * mag / 8.55
                wait(0.1)
                Static1.ImageTransparency = 0.75 * mag / 8.55
                wait(0.1)
                Static1.ImageTransparency = 0.25 * mag / 8.55
                wait(0.1)
                Static1.ImageTransparency = 0.9 * mag  / 8.55
                wait(0.1)

            else

                local StaticMain = script.Parent.StaticGUI
                local Static1 = StaticMain.Static1
                local StaticSound = script.StaticSound

                StaticMain.Enabled = false
                StaticSound.Playing = false

            end;
        end;
    end)()

    local IsSeen = StartUITrack(WG["Meshes/thehead"])
    if IsSeen == true then

    end

end

any help is appreciated, thank you in advance

Answer this question