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

attempt to index upvalue 'part2' (a nil value) Why does this keep doing this? I'm so confused

So this may be really simple, but I have no idea how to fix this. And I literally tried everything I can do. This is a new attack script for one of my game. And it keeps saying this:

14:55:38.123 - Players.Player.Backpack.Tremor Punch:95: attempt to index upvalue 'part2' (a nil value) 14:55:38.124 - Stack Begin 14:55:38.125 - Script 'Players.Player.Backpack.Tremor Punch', Line 95 14:55:38.125 - Stack End

Everything is working fine till it gets to that. Which its a local. Here I'll paste the script:

-- Tremor Punch, made by Coldcce.

player = script.Parent.Parent
mouse = player:GetMouse()
animation = script:WaitForChild("Animation")
animation2 = script:WaitForChild("Animation2")
isplaying = false

bin = script.Parent
Backpack = bin.Parent
me = Backpack.Parent

damage = 15
buttonOn = false

char = player.Character

larm = char:FindFirstChild("Left Arm")
rarm = char:FindFirstChild("Right Arm")

enabled = true

local uis = game:GetService("UserInputService") --The service
local plyr = game:GetService("Players").LocalPlayer

local part2 = part2

uis.InputBegan:connect(function(Key, Processed)
	if Key.KeyCode == Enum.KeyCode.X and not Processed then
		if buttonOn == false then
		buttonOn = true			
		if isplaying == false then
			isplaying = true
			local animationp = player.Character.Humanoid:LoadAnimation(animation)
			animationp:Play()
			player.Character.Humanoid.WalkSpeed = 0
			wait(1)
				
			local part2 = Instance.new("Part")
			part2.BrickColor = BrickColor.new("Light blue")
			part2.Parent = larm
			part2.Name = "part2"
			part2.Size = Vector3.new(2.5, 2.5, 2.5)
			part2.TopSurface = "Smooth"
			part2.BottomSurface = "Smooth"
			part2.FormFactor = "Symmetric"
			part2.Shape = "Ball"
			part2.Transparency = 0.8
			part2.CFrame = larm.CFrame
			part2.Material = "Neon"		
			
			local f = Instance.new('BodyForce')
			f.force = Vector3.new(0, 0, 50)
			f.Parent = part2
			
			local Owner = Instance.new("ObjectValue")
			Owner.Parent = part2
			Owner.Name = "Owner"
			Owner.Value = me
			
			local sound = Instance.new("Sound")
			sound.SoundId = "http://www.roblox.com/asset/?id=315030459"
			sound.Parent = part2
			sound.Volume=1
			sound.Pitch=1
			sound:Play()
			
			local e = script.ArrowScript:clone()
			e.Parent = part2
			e.Disabled = false
			
			local weld = Instance.new("Weld", char)
			weld.Part0 = weld.Parent["Left Arm"]
			weld.Part1 = part2
			weld.C1 = CFrame.fromEulerAnglesXYZ (0, 0, 0) *CFrame.new (0, 1.5, 0)
			weld = Instance.new("Weld", char)
			weld.Part0 = part2
			weld.C1 = CFrame.fromEulerAnglesXYZ (0, 0, 0) *CFrame.new (0, 0, 0)
	for i = 1,6 do
		wait(0.2)		
		part2.Transparency = part2.Transparency - 0.1
		player.Character.Humanoid.WalkSpeed = 18
		end
		end
		end	
	uis.InputEnded:connect(function(Key, Processed)
    if Key.KeyCode == Enum.KeyCode.X and not Processed then
	
			local animationd = player.Character.Humanoid:LoadAnimation(animation2)
			animationd:Play()
			player.Character.Humanoid.WalkSpeed = 0
			player.Character.Torso.Anchored = true
			
			wait(3)
			part2:remove()
			player.Character.Torso.Anchored = false
			player.Character.Humanoid.WalkSpeed = 16
			wait(5)
			buttonOn = false
			isplaying = false
	end
	end)
end
end)

I've tried local, global at the top, workspace global, and all of that. I don't know everything yet. I'm still learning this Roblox Scripting stuff.

I've been trying to fix this problem last night around 4-6 AM. And non of it worked. I've been trying for a hour now to fix it too. Nothing has worked.

Someone please help me.

2 comments

0

You defined part2 twice in your script. I believe you were only suppose to define it once for the part to be created through the instance.

0

Yea, I fixed that after I posted this. Thank you minikitkat! :D

2 answers

✓ Accepted answer

Hey there, it appears that you're trying to access an instance later on in the script as a directory. This is not possible as 'Part2' is not an actual directory. You could do the following to fix this

--Simply add this to your script where it appropriately belongs and edit if needed--

 A = larm:GetChildren()
for i,v in pairs(A) do --Gets larm's children
	if v.Name == "part2" then --Checks if a child has this name
		 v:Remove() --Removes the child
	end
end

If this worked make sure to accept! If it didn't please comment and I'll try my hardest to help you fix it further. Hoped this helped!!

-- Tremor Punch, made by Coldcce.

player = script.Parent.Parent
mouse = player:GetMouse()
animation = script:WaitForChild("Animation")
animation2 = script:WaitForChild("Animation2")
isplaying = false

bin = script.Parent
Backpack = bin.Parent
me = Backpack.Parent

damage = 15
buttonOn = false

char = player.Character

larm = char:FindFirstChild("Left Arm")
rarm = char:FindFirstChild("Right Arm")

enabled = true

local uis = game:GetService("UserInputService") --The service
local plyr = game:GetService("Players").LocalPlayer

local part2 = part2--Remove this as it is unnecessary.

uis.InputBegan:connect(function(Key, Processed)
    if Key.KeyCode == Enum.KeyCode.X and not Processed then
        if buttonOn == false then
        buttonOn = true         
        if isplaying == false then
            isplaying = true
            local animationp = player.Character.Humanoid:LoadAnimation(animation)
            animationp:Play()
            player.Character.Humanoid.WalkSpeed = 0
            wait(1)

            local part2 = Instance.new("Part")--As u can see u already defined it correctly later on in the script to create a part.
            part2.BrickColor = BrickColor.new("Light blue")
            part2.Parent = larm
            part2.Name = "part2"
            part2.Size = Vector3.new(2.5, 2.5, 2.5)
            part2.TopSurface = "Smooth"
            part2.BottomSurface = "Smooth"
            part2.FormFactor = "Symmetric"
            part2.Shape = "Ball"
            part2.Transparency = 0.8
            part2.CFrame = larm.CFrame
            part2.Material = "Neon"     

            local f = Instance.new('BodyForce')
            f.force = Vector3.new(0, 0, 50)
            f.Parent = part2

            local Owner = Instance.new("ObjectValue")
            Owner.Parent = part2
            Owner.Name = "Owner"
            Owner.Value = me

            local sound = Instance.new("Sound")
            sound.SoundId = "http://www.roblox.com/asset/?id=315030459"
            sound.Parent = part2
            sound.Volume=1
            sound.Pitch=1
            sound:Play()

            local e = script.ArrowScript:clone()
            e.Parent = part2
            e.Disabled = false

            local weld = Instance.new("Weld", char)
            weld.Part0 = weld.Parent["Left Arm"]
            weld.Part1 = part2
            weld.C1 = CFrame.fromEulerAnglesXYZ (0, 0, 0) *CFrame.new (0, 1.5, 0)
            weld = Instance.new("Weld", char)
            weld.Part0 = part2
            weld.C1 = CFrame.fromEulerAnglesXYZ (0, 0, 0) *CFrame.new (0, 0, 0)
    for i = 1,6 do
        wait(0.2)       
        part2.Transparency = part2.Transparency - 0.1
        player.Character.Humanoid.WalkSpeed = 18
        end
        end
        end 
    uis.InputEnded:connect(function(Key, Processed)
    if Key.KeyCode == Enum.KeyCode.X and not Processed then

            local animationd = player.Character.Humanoid:LoadAnimation(animation2)
            animationd:Play()
            player.Character.Humanoid.WalkSpeed = 0
            player.Character.Torso.Anchored = true

            wait(3)
            part2:remove()
            player.Character.Torso.Anchored = false
            player.Character.Humanoid.WalkSpeed = 16
            wait(5)
            buttonOn = false
            isplaying = false
    end
    end)
end
end)

If this helped be sure to accept it. If it didn't post a comment about it and I'll try to help you out as best as I can ty!

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