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

Players.(me).Backpack.Mera.Fly:59: attempt to index nil with 'remove' help me with this plz?

Asked by 3 years ago

here is my code :

 repeat wait() until game.Players.LocalPlayer.Character

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local Torso = char:WaitForChild("Head")
local Wing = char:WaitForChild("LowerTorso")
local Storage = game.ReplicatedStorage.Mera.Fly
local B1 = Storage.Fire1:Clone()
local B2 = Storage.Fire2:Clone()
local B3 = Storage.Fire3:Clone()
local B4 = Storage.Fire4:Clone()
local Mouse = plr:GetMouse()
local toggle = true
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://5448928051"
local PlayAnim = hum:LoadAnimation(Anim)
Mouse.KeyDown:Connect(function(key)
    if key == "f" and script.Parent.Equip.Value == true then
B1.Parent = Wing
B2.Parent = Wing
B3.Parent = Wing
B4.Parent = Wing
        if toggle == false then
            toggle = true
            B3.Enabled = true
            B1.Enabled = true
            B2.Enabled = true
            B4.Enabled = true
            hum.PlatformStand = true
    plr.Character.LeftUpperLeg.Transparency = 1
    plr.Character.RightUpperLeg.Transparency = 1
    plr.Character.LeftLowerLeg.Transparency = 1
    plr.Character.RightLowerLeg.Transparency = 1
    plr.Character.LeftFoot.Transparency = 1
            plr.Character.RightFoot.Transparency = 1
            PlayAnim:Play()
            local BV = Instance.new("BodyVelocity",Torso)
            BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
            while toggle == true do
                BV.Velocity = Mouse.Hit.lookVector*45 -- Speed
                Torso.CFrame = CFrame.new(Torso.Position,Mouse.Hit.p)
                wait(0.1)
            end
        end
        if toggle == true then
            toggle = false
            B1.Enabled = false
            B2.Enabled = false
            B3.Enabled = false
            B4.Enabled = false
            hum.PlatformStand = false
    plr.Character.LeftUpperLeg.Transparency = 0
    plr.Character.RightUpperLeg.Transparency = 0
    plr.Character.LeftLowerLeg.Transparency = 0
    plr.Character.RightLowerLeg.Transparency = 0
    plr.Character.LeftFoot.Transparency = 0
    plr.Character.RightFoot.Transparency = 0
            Torso:FindFirstChildOfClass("BodyVelocity"):remove()
            local tracks = hum:GetPlayingAnimationTracks()
            for i, stoptracks in pairs(tracks) do
                stoptracks:Stop(1000)
            end
            PlayAnim:Stop(100)
        end
    end
end)
1
maybe change capitalization? (what i mean is replace remove() with Remove()), if that doesn't work, do Destroy() instead of Remove() NGC4637 602 — 3y
0
nah didnt work wyatt447 16 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

That error usually happens when the object you are trying to modify doesn't exist, you should make sure the object actually exists before running :Remove() on it. You Could Replace Your Code On Line 59 With This: if Torso:FindFirstChildOfClass("BodyVelocity") then Torso:FindFirstChildOfClass("BodyVelocity"):remove() end

0
thx its working now :) wyatt447 16 — 3y
0
No problem. :D KeithKeiser971 15 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I would use Destroy() instead of remove(). Idk what remove() even is.

0
I agree that remove shouldn't be used, as it is deprecated, but it still functions for backwards compatability. If you want to know the difference between remove and destroy you can read here: https://scriptinghelpers.org/questions/15726/what-is-the-difference-between-remove-and-destroy KeithKeiser971 15 — 3y

Answer this question