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

why does my raycast activate through walls?

Asked by
Foxxive 10
2 years ago

hello, after making THREE posts and not getting help on any of them this is my last attempt at making a post so hopefully, someone can help me out here

I’m making a slenderman game on Roblox and I’m trying to get the static GUI to work when slender is being looked at. However, the GUI can still activate through walls for some reason even though I scripted the raycast stuff.

here’s my code (the whole thing lol):

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/thehead"].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 greatly appreciated, thank you in advance

Answer this question