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

Raycast wont detect parts half the time?

Asked by 2 years ago
Edited 2 years ago

for some reason, even if i dont move my mouse my raycast wont detect it hit a part, but other times it does. i have no clue whats causing it though and i cant find anything about it that works for my problem

what it looks like: https://youtu.be/AmsPRP-sEzg (it shoots off to the side if the ray doesn't hit anything)

local code:

FunniCooldown =  false
Poss = Vector3
Poss2 = Vector3
Hit = Instance
script.Parent.Activated:Connect(function()
    if FunniCooldown == false then
        wait(0.025)
        print("Shot")
        FunniCooldown = true
        local mouse = game.Players.LocalPlayer:GetMouse()
        local poss = mouse.Hit.Position - script.Parent.Handle.ShootPoint.WorldPosition
        local RayParams = RaycastParams.new()   
        RayParams.FilterDescendantsInstances = {script.Parent.Parent}
        RayParams.FilterType = Enum.RaycastFilterType.Blacklist

        local RayResult = workspace:Raycast(script.Parent.Handle.ShootPoint.WorldPosition, poss, RayParams)
        wait(0.1)
        if RayResult ~= nil then
            print("Ray hit somin")      
            Poss = RayResult.Position       
            Hit = RayResult.Instance
        elseif RayResult == nil then
            Poss = Vector3.new(0,0,0)
            print("Ray it nothing")
        end
        Poss2 = script.Parent.Handle.ShootPoint.WorldPosition
        script.Parent.FireRemoteEvent:FireServer(Poss, Poss2)
        wait(0.25)
        FunniCooldown = false
    end
end)

server code: (only does the trail and animation stuff rn)

script.Parent.FireRemoteEvent.OnServerEvent:Connect(function(Player, Poss, Poss2)
    script.Parent.BulletTrailEnd.Position = Poss
    script.Parent.BulletTrailStart.Position = Poss2
    script.Parent.Handle.FireSound:Play()
    script.Parent.BulletTrailEnd.ShootHit.Beam.Width0 = 0.15
    script.Parent.BulletTrailEnd.ShootHit.Beam.Width1 = 0.15
    local TweenService = game:GetService("TweenService")

    local tweenInfo = TweenInfo.new(
        0.15, -- Time
        Enum.EasingStyle.Linear, -- EasingStyle
        Enum.EasingDirection.In, -- EasingDirection
        0, -- RepeatCount (when less than zero the tween will loop indefinitely)
        false, -- Reverses (tween will reverse once reaching it's goal)
        0 -- DelayTime
    )
    local tween0 = TweenService:Create(script.Parent.BulletTrailEnd.ShootHit.Beam, tweenInfo, {Width0 = 0})
    local tween1 = TweenService:Create(script.Parent.BulletTrailEnd.ShootHit.Beam, tweenInfo, {Width1 = 0})
    tween0:Play()
    tween1:Play()
    local amin = script.Parent.SwingAnim
    local anim = script.Parent.Parent.Humanoid:LoadAnimation(amin)
    anim:Play()
end)

any help would be appreciated

Answer this question