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

What is index upvalue and how can I fix it?

When I load into my game, I'm greeted with this lovely error that spams the console: http://prnt.sc/evower

This is the code that it references:

local Rotation = Vector3.new(Mouse.Hit.X,  Torso.CFrame.Y,  Mouse.Hit.Z)

What is causing the error and how can I go about fixing it? I'm not one to normally ask for help, but this really has me stumped.

Full Function:

local Player = game.Players.LocalPlayer
local Char = Player.Character
local Torso = Char:WaitForChild("Torso",0.1)
local events = {}

local bv = Instance.new("BodyGyro",Torso)
bv.maxTorque=Vector3.new(math.huge,math.huge,math.huge)
bv.P = 15000

local bag_tag = nil
local npc_tag = nil

events[#events + 1] = Mouse.Move:connect(function()
	local Rotation = Vector3.new(Mouse.Hit.X,  Torso.CFrame.Y,  Mouse.Hit.Z)
	bv.cframe=CFrame.new(Torso.CFrame.p,  Rotation)
	if(Mouse.Target ~= nil) then
		local tar = Mouse.Target
		if(tar.Parent == game.Workspace.Parts.Item_Bags) then
			if(tar:FindFirstChild("Item") and tar:FindFirstChild("User")) then
				make_bag_tag(tar)
				elseif(bag_tag) then
					bag_tag:Destroy()
					bag_tag = nil
				end
				elseif(bag_tag) then
					bag_tag:Destroy()
					bag_tag = nil
				end
				if(tar.Parent.Parent == game.Workspace.Mobs.NPC) then
					if(tar.Parent:FindFirstChild("Head")) then
						make_npc_tag(tar.Parent)	
					elseif(npc_tag) then
						npc_tag:Destroy()
						npc_tag = nil
					end
				elseif(npc_tag) then
					npc_tag:Destroy()
					npc_tag = nil
				end
		else
		if(bag_tag) then
			bag_tag:Destroy()
			bag_tag = nil
		end
		if(npc_tag) then
			npc_tag:Destroy()
			npc_tag = nil
		end
	end
end)

4 comments

0

Try just having ":WaitForChild("Torso")" instead, as it may have timed out before it could get the torso.

0

When I remove the time value, it doesn't function at all and then just says infinite yield possible

0

Are you using R15? If so, you should use "UpperTorso" instead of "Torso".

0

That was the issue, thanks.

1 answer

✓ Accepted answer
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Torso = Char:WaitForChild("Torso",0.1)
local events = {}

local bv = Instance.new("BodyGyro",Torso)
bv.maxTorque=Vector3.new(math.huge,math.huge,math.huge)
bv.P = 15000

local bag_tag = nil
local npc_tag = nil

events[#events + 1] = Mouse.Move:connect(function()
    local Rotation = Vector3.new(Mouse.Hit.X,  Char:WaitForChild("Torso").CFrame.Y,  Mouse.Hit.Z)
    bv.cframe=CFrame.new(Torso.CFrame.p,  Rotation)
    if(Mouse.Target ~= nil) then
        local tar = Mouse.Target
        if(tar.Parent == game.Workspace.Parts.Item_Bags) then
            if(tar:FindFirstChild("Item") and tar:FindFirstChild("User")) then
                make_bag_tag(tar)
                elseif(bag_tag) then
                    bag_tag:Destroy()
                    bag_tag = nil
                end
                elseif(bag_tag) then
                    bag_tag:Destroy()
                    bag_tag = nil
                end
                if(tar.Parent.Parent == game.Workspace.Mobs.NPC) then
                    if(tar.Parent:FindFirstChild("Head")) then
                        make_npc_tag(tar.Parent)    
                    elseif(npc_tag) then
                        npc_tag:Destroy()
                        npc_tag = nil
                    end
                elseif(npc_tag) then
                    npc_tag:Destroy()
                    npc_tag = nil
                end
        else
        if(bag_tag) then
            bag_tag:Destroy()
            bag_tag = nil
        end
        if(npc_tag) then
            npc_tag:Destroy()
            npc_tag = nil
        end
    end
end)

Upvalue means ou have 2 arguements witht eh same name confusing teh target so insteadt of Torso.CFrame.Y do Char.Torso.CFrame.Y

If this worked please upvote and accept this answer.

6 comments

0

Doesn't give me index upvalue anymore, but it now says Torso is not a valid member of Model

0

hmm

0

Try it now also what is the meaning of the second parameter of Torso

0

The second parameter's meaning if the time is exceeded it returns nil that is probably why it didn't work.

0

Someone answered it for me above, but I'll still upvote since your answer did kinda help

0

oh heh thx

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