I have a script that shrinks a part that the player touches. Instead of having to insert the same script in hundreds of different parts (Which creates lag) my goal is to have one single script control all the parts with a certain name (i.e ShrinkingPart) to shrink. This is the script for each part.
local debounce = true local d = script.Parent.Decal t = 0.06 function onTouched(hit) if (debounce == true) then debounce = false wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) wait(t) script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x-0.05,script.Parent.Mesh.Scale.y,script.Parent.Mesh.Scale.z-0.05) script.Parent.CanCollide = false script.Parent.Transparency = 1 d.Parent = nil wait(3) d.Parent = script.Parent script.Parent.CanCollide = true script.Parent.Mesh.Scale = Vector3.new(1,1,1) script.Parent.Transparency = 0 debounce = true end end connection = script.Parent.Touched:connect(onTouched)
You’re wrapping your if statement in brackets, and using deprecated code.
And Dude! You don’t need so many lines!! Use a for loop!
function onTouched(part) mesh = script.Parent.Mesh --use more variables !! if debounce == true then -- don’t wrap this in brackets! debounce = false for i = 1, .05, -.01 do mesh.Scale = Vector3.new( mesh.Scale.x - .05, mesh.Scale.y, mesh.Scale.y -.05 wait(t) ) end script.Parent.CanCollide = false script.Parent.Transparency = 1 d.Parent = nil wait(3) script.Parent.CanCollide = true script.Parent.Mesh.Scale = Vector3.new(1,1,1) script.Parent.Transparency = 0 debounce = true end end script.Parent.Touched:Connect(onTouched)