#Workspace.1ceKarim.Mechanics.Vault:21: attempt to index nil with 'Instance'

1 messages · Page 1 of 1 (latest)

coral sorrel
#
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
local humanoid = char:FindFirstChildOfClass("Humanoid")
local climbAnim = humanoid:LoadAnimation(script:WaitForChild("Climb"))

local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local debounce = false
local part = false
local vaultCheck

while runService.RenderStepped:Wait() do
    local params = RaycastParams.new()
    params.FilterDescendantsInstances = {char}
    params.FilterType = Enum.RaycastFilterType.Exclude
    
    local ray = workspace:Raycast(humanoidRootPart.Position, humanoidRootPart.CFrame.LookVector * 7 + humanoidRootPart.CFrame.UpVector * -0.5, params)
    
    if ray.Instance ~= nil and debounce == false then
        local rayPart = ray.Instance
        
        if rayPart:HasTag("Vault") then
            if humanoid.FloorMaterial ~= Enum.Material.Air then
                debounce = true
                local velocity = Instance.new("BodyVelocity")
                velocity.Parent = humanoidRootPart
                velocity.Velocity = Vector3.new(0,0,0)
                velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
                velocity.Velocity = humanoidRootPart.CFrame.LookVector * 20 + Vector3.new(0, 15, 0)
                game.Debris:AddItem(velocity, 0.2)
                climbAnim:Play()
                task.wait(0.7)
                debounce = false
            end
        end
    end
end