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

My mafia gun that appears on the left arm appears to not get the NPCs/Players position?

Asked by 2 years ago

So I made a gun where If you equip It and click on a Player or a NPC It will Instantly kill them, however It appears there was a error In the output the error says "Unable to cast values to Objects", here Is the script:

tool.Fire.OnServerEvent:Connect(function(player,mousePos)
    Pew:Play() ---This just plays a sound btw

    local raycastParams = RaycastParams:new()
    raycastParams.FilterDescendantsInstances = (player.Character)
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

    local raycastResult = workspace:Raycast(script.Parent.Pistol.Position,(mousePos - script.Parent.Pistol.Position)*1000,raycastParams)

    if raycastResult then
        local HitPart = raycastResult.Instance
        local model = HitPart:FindFirstAncestorOfClass("Model")

        if model then
            if model:FindFirstChild("Humanoid") then
                model.Humanoid.Health -= 100
            end
        end
    end


end)

Answer this question