Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

1

maybe change capitalization? (what i mean is replace remove() with Remove()), if that doesn't work, do Destroy() instead of Remove()

0

nah didnt work

2 answers

✓ Accepted answer

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

2 comments

0

thx its working now :)

0

No problem. :D

This discussion is preserved as it was. New answers, comments, and votes are closed.