I want to make my character click a button to get bigger.
There are no errors in the output.
local button = script.Parent.Parent
local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function(player)
local char = player.Character
local Human = char.Humanoid
local depth = Human:WaitForChild("BodyDepthScale")
local height = Human:WaitForChild("BodyHeightScale")
local width = Human:WaitForChild("BodyWidthScale")
local head = Human:WaitForChild("HeadScale")
local properties = {depth, height, width, head}
for i,property in pairs(properties) do
wait(1)
local changeBy = math.random(-1, 1)
property.Value = property.Value + changeBy
end
end)
I tried this and it works.
Seems to be the changeBy variable causing the problem
local Button = script.Parent.Parent
local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function(Player)
local Char = Player.Character
local Human = Char.Humanoid
local Depth = Human:WaitForChild("BodyDepthScale")
local Height = Human:WaitForChild("BodyHeightScale")
local Width = Human:WaitForChild("BodyWidthScale")
local Head = Human:WaitForChild("HeadScale")
local Properties = {Depth, Height, Width, Head}
for _, Property in pairs(Properties) do
Property.Value = math.random(50, 150) / 100
end
end)
I’d rather use :FindFirstChild instead of :WaitForChild since the child you are searching for is already inside humanoid when a player is going to click on the click detector and you don’t have to wait for it to be added there. You might not face an error but because of that, you might receive a warning called infinite yield possible.
local button = script.Parent.Parent
local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function(player)
local char = player.Character
if char then
local Human = char:FindFirstChild("Humanoid")
if Human then
local depth = Human:FindFirstChild("BodyDepthScale")
local height = Human:FindFirstChild("BodyHeightScale")
local width = Human:FindFirstChild("BodyWidthScale")
local head = Human:FindFirstChild("HeadScale")
local properties = {depth, height, width, head}
for i,property in pairs(properties) do
if property then
property.Value += 1
end
end
end
end
end)