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

Why is my script not working using "v" as a child of "hit.Parent"?

So, I have a script. This script is in a part. When I step on the part, I want all body parts of the player(hit.Parent.v) to shrink to 0.5. But nothing works. I'm betting it's something to do with the "hit.Parent.v" part. Here's the script:

local part = script.Parent
local db = false

function shrink(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if human then
		if not db then
			
			db = true
			
			local player = human.Parent
			local myArray = {"Left Leg","Right Leg","Left Arm","Right Arm","Torso","Head"}
			
			for i,v in pairs(myArray) do
				hit.Parent.v.Size = 0.5
			end
			
		end
	end
end

part.Touched:connect(shrink)

All help is appreciated!

1 answer

✓ Accepted answer

You can't index using a variable like that. Use SquareBrackets instead. Also, you have to use a Vector3 to set the size of a part.

local part = script.Parent
local db = false

function shrink(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    if human then
        if not db then

            db = true

            local player = human.Parent
            local myArray = {"Left Leg","Right Leg","Left Arm","Right Arm","Torso","Head"}

            for i,v in pairs(myArray) do
                hit.Parent[v].Size = Vector3.new(0.5, 0.5, 0.5)
            end
        end
    end
end

part.Touched:Connect(shrink)

Good Luck!

If I helped, don't forget to accept my answer.

1 comment

0

Thanks! Now, I just need to fix that the person dies ._.

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