How to change the size of a characters legs after a click?

  1. What do you want to achieve? I want to make a character’s legs bigger after you click

  2. image

  3. What solutions have you tried so far? I’ve tried searching on google to see if anyone else has tried the same thing

Heres my script:

local plr = game.Players.LocalPlayer
local char = plr.Character or script.Parent
local hum = char:WaitForChild("Humanoid")
local mouse = plr:GetMouse()
local legs = {
	
	char:WaitForChild("LeftLowerLeg"),
	char:WaitForChild("LeftUpperLeg"),
	char:WaitForChild("RightLowerLeg"),
	char:WaitForChild("RightUpperLeg")
	
}



mouse.Button1Up:Connect(function()
	
	for i, v in pairs(legs) do
		
	v.Size = Vector3.new(v.Size) + Vector3.new(.1,.1,.1)
		
	end
end)

There are many things wrong here. Let me post a logical solution first

local plr = game.Players.LocalPlayer
local char = plr.Character or script.Parent
local mouse = plr:GetMouse()
local legs = {
	char:WaitForChild("LeftLowerLeg"),
	char:WaitForChild("LeftUpperLeg"),
	char:WaitForChild("RightLowerLeg"),
	char:WaitForChild("RightUpperLeg")
}

mouse.Button1Up:Connect(function()
	for _, leg in ipairs(legs) do -- loops through the legs table
		-- individually increase each leg's size
		leg.Size = leg.Size + Vector3.new(.1, .1, .1)
	end
end)

So what did I do? Well, the main logical issue you face is that you are trying to increase all the legs sizes by referencing the table. You have to loop through the table like I did above and access each leg part individually in order to resize it.

Firstly, it’s important to mention that your code is still invalid, though it can work error-free. the main issue is that you are modifying the size on the client instead of the server. Changing the size of the legs on the client makes it so that only you can see the legs change size, not other players.

To make the growth replicate (which means it grows on the server) you have to fire a RemoteEvent from the client to the server. Detecting the mouse input is done on the client via a LocalScript, while all the resizing would be done on the server using a ServerScript.

Secondly, the mouse object is legacy and should be replaced by UserInputService

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
		-- loop
	end
end)

3 Likes