How Do I Activate A Tween If A Part Touches Something?

How Do I Activate A Tween If A Part Touches Something because idk how

script for the tween:

local TweenService = game:GetService("TweenService")

local player = game.ReplicatedStorage.Events.Tsunami

local part = game.Workspace.Blocker
part.Size = Vector3.new(213.299, 138.575, 4.386)

local goal = {}
goal.Size = Vector3.new(24, 34.458, 4.386)

local tweenInfo = TweenInfo.new(
	10,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0)

local tween = TweenService:Create(part, tweenInfo, goal)


wait(3)
tween:Play()
wait(10.3)
script.Parent.Transparency = 1

screenshot:

any help will work and post the script and always no errors oops i accidentaly deleted this topic

1 Like

Is your script disabled? Looks like it though.

no i was asking if the part touches another part
the script will enable

Oh, sorry. Okay, so when it touches the player’s character?

no not the player character i mean another part

local TweenService = game:GetService("TweenService")

local player = game.ReplicatedStorage.Events.Tsunami

local part = game.Workspace.Blocker
part.Size = Vector3.new(213.299, 138.575, 4.386)

local goal = {}
goal.Size = Vector3.new(24, 34.458, 4.386)

local tweenInfo = TweenInfo.new(
	10,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0)

local tween = TweenService:Create(part, tweenInfo, goal)
local debounce = false
-- Having a debounce so it has a cooldown

part.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        
        if hit.Name == "ThePartName" then -- If the touched part's name is the part name we're looking for then we'll play the tween
            tween:Play()
        end
        
        task.wait(1)
        debounce = false
    end
end)

tween.Completed:Connect(function()
    -- Your code when the tweening is complete.
end)

Explained a few stuff, you can ask more if you don’t understand!

tween still plays without the part touching it

Weird. Maybe add a print statement after debounce and print out the name of the ‘hit’?

Edit: Instead of the name checking you can do this

if hit == game.Workspace.YourPart then -- Pretty sure it should work

still plays without the part hitting it

and it plays too many times i added print(“hit”) only if i touch it

Scripts cant enable other scripts

local TweenService = game:GetService("TweenService")

local player = game.ReplicatedStorage.Events.Tsunami

local part = game.Workspace.Blocker
part.Size = Vector3.new(213.299, 138.575, 4.386)

local debounce = false
-- Having a debounce so it has a cooldown

part.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        
        if hit.Name == "ThePartName" then -- If the touched part's name is the part name we're looking for then we'll play the tween
            local goal = {}
            goal.Size = Vector3.new(24, 34.458, 4.386)

            local tweenInfo = TweenInfo.new(
	            10,
	            Enum.EasingStyle.Linear,
	            Enum.EasingDirection.Out,
	            0,
	            false,
	        0)

            local tween = TweenService:Create(part, tweenInfo, goal)
            tween:Play()
        end
        
        task.wait(1)
        debounce = false
    end
end)

tween.Completed:Connect(function()
    -- Your code when the tweening is complete.
end)

Try creating the tween inside the Touched event?

script.Parent.Touched:Connect(function(hit)
  if hit then
       workspace.Blocker.Size = Vector3.new(213.299, 138.575, 4.386)
       TweenService:Create(workspace.Blocker, TweenInfo.New(10), {Size = Vector3.new(24, 34.458, 4.386)}):Play()
    end
end)

still plays the tween without the part hitting another part

Is there any other scripts that play the same tween?

I told you, Scripts cant enable other scripts. Use events.

Wrong, they can.


“Disabling” → Script that sets the Disabled property to false for another script
“yes” → Script that is disabled.

I never knew that. For security reasons i dont think you should.