I have tried making a power up in my game that would shrink the player down, however on touch it doesn’t work. No errors seem to be popping up. Anyone know of a way to make this work?
script.Parent.Touched:Connect(function(touched)
if touched.Parent:FindFirstChild("Humanoid") then
Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.HeadScale *= 0.5
Humanoid.BodyDepthScale *= 0.5
Humanoid.BodyWidthScale *= 0.5
Humanoid.BodyHeightScale *= 0.5
end
end)
script.Parent.Transparency = 0.50
wait(10)
Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.HeadScale *= 2
Humanoid.BodyDepthScale *= 2
Humanoid.BodyWidthScale *= 2
Humanoid.BodyHeightScale *= 2
end
end)
script.Parent.Transparency = 1
end
end)
(The transparency lines just make the part transparent to show the player picked them up)
First of all, you should probably use FindFirstAncestorWhichIsA(“Model”) instead of touched.Parent. If it touches an accessory it will not work, although this isn’t necessary.
With scaling, I think it should be = 0.5, rather than *= 0.5. (Same with the *= 2)
You just made a common mistake, the values you are trying to change are actual NumberValues/IntValues inside of the Humanoid (not a property of it). You just need to change it’s .Value instead of the whole instance.
local canTouch = true
local function multiplyScale(Humanoid, Scale)
if Humanoid then
Humanoid.HeadScale.Value *= Scale
Humanoid.BodyDepthScale.Value *= Scale
Humanoid.BodyWidthScale.Value *= Scale
Humanoid.BodyHeightScale *= Scale
end
end
script.Parent.Touched:Connect(function(hitPart)
local Model = hitPart:FindFirstAncestorWhichIsA("Model")
if Model then
local Humanoid = Model:FindFirstChildOfClass("Humanoid")
if Humanoid then
canTouch = false
script.Parent.Transparency = 0.5
multiplyScale(Humanoid, 0.5)
task.wait(10)
multiplyScale(Humanoid, 2)
script.Parent.Transparency = 0
canTouch = true
end
end
end)