0

# how do i make it so when you touch the scripts parent it starts shrinking?

i tried to do it on my own but it doesnt work im new to scripting

local player = game:GetService("Players").LocalPlayer script.Parent.Touched:Connect(function(hit) if hit.Parent == player.Character then script.Parent.Size = script.Parent.Size - Vector3.new(0.25,0,0.25) end end)

0

Hello here's your solution. You can use loops repeat the size decreasing!

local debounce = true -- make it so if the part is touched then it wont repeat the code while your touching it
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Humanoid ~= nil then --check if the thing that touched it is a player
if debounce == true then --check if debounce is true
debounce = false --make debounce false in order to make sure code isnt spammed
for i = 1,50 do --repeat following code 50 times, change this to "while true do" if you want this to start shrinking forever
wait(0.01) --wait time every time it repeats
script.Parent.Size = script.Parent.Size - Vector3.new(0.01,0.01,0.01)
end
wait(0.5)
debounce = true --enable debounce again
end
end
end)

0

Loops don't always work, for smoother movement, I would recommend the TweenService. While it seems complicated at first it's not too bad once you get a hold of it. Also if this is a Script you can't use Players.LocalPlayer, if it is a Local Script you should change it to a Script object.

In your case, the script would look like this:

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(10) --Set the number to how long you want it to take to shrink

local part = script.Parent --Set this to the part you want to shrink
local goalSize = Vector3.new(1,1,1) -- Set this to the size you want the part to shrink to

local tween = TweenService:Create(part,tweenInfo,{Size = goalSize}) --Create the Tween

script.Parent.Touched:Connect(function(hit)
if hit:FindFirstAncestorWhichIsA("Model") then --:FindFirstAncestorWhichIsA is the best way to find model object
tween:Play() --Runs Tween, shrinks to 1,1,1 over 10 seconds
end
end)