Hi, I’m trying to make a part guarding a small room where it’s been enlarged to act as hitbox. However, I noticed that Touched event don’t work with currently playing tweened parts and I tried looking up articles for help but none of them really helped. Is there a different way that I can make this work?
My localscript for it:
local localplayer = game:GetService("Players").LocalPlayer
local tweenservice = game:GetService("TweenService")
local debounce = true
local cam = workspace.Camera
local viewport_size = cam.ViewportSize
local goalfirst = {}
goalfirst.Position = Vector3.new(-775.391, 7.435, 771.918)
local goalsecond = {}
goalsecond.Position = Vector3.new(-775.391, 7.435, 674.918)
local goalthird = {}
goalthird.Position = Vector3.new(-826.391, 7.435, 674.918)
local goalfourth = {}
goalfourth.Position = Vector3.new(-826.391, 7.435, 771.418)
local goalfinal = {}
goalfinal.Position = Vector3.new(-936.891, 7.435, 771.418)
local goalteleport = {}
goalteleport.Position = Vector3.new(-674.891, 7.435, 771.918)
local turnright = {}
turnright.Orientation = workspace.sillyguard.Orientation + Vector3.new(0,-90,0)
local turnleft = {}
turnleft.Orientation = workspace.sillyguard.Orientation + Vector3.new(0,89.9,0)
local straight = {}
straight.Orientation = workspace.sillyguard.Orientation + Vector3.new(0,0,0)
local invisible = {}
invisible.Transparency = 1
local visible = {}
visible.Transparency = 0
local tweeninfosilly = TweenInfo.new(3, Enum.EasingStyle.Linear)
local tweeninfosilly2 = TweenInfo.new(1.5, Enum.EasingStyle.Linear)
local tweensilly1 = tweenservice:Create(workspace.sillyguard, tweeninfosilly, goalfirst)
local tweensilly2 = tweenservice:Create(workspace.sillyguard, tweeninfosilly2, turnright)
local tweensilly3 = tweenservice:Create(workspace.sillyguard, tweeninfosilly, goalsecond)
local tweensilly4 = tweenservice:Create(workspace.sillyguard, tweeninfosilly2, turnleft)
local tweensilly5 = tweenservice:Create(workspace.sillyguard, tweeninfosilly, goalthird)
local tweensilly6 = tweenservice:Create(workspace.sillyguard, tweeninfosilly, goalfourth)
local tweensilly7 = tweenservice:Create(workspace.sillyguard, tweeninfosilly, goalfinal)
local tweensilly8 = tweenservice:Create(workspace.sillyguard, tweeninfosilly2, invisible)
local tweensilly9 = tweenservice:Create(workspace.sillyguard, tweeninfosilly2, visible)
local tweensilly10 = tweenservice:Create(workspace.sillyguard, tweeninfosilly2, straight)
while true do
tweensilly1:Play()
tweensilly1.Completed:Wait()
tweensilly2:Play()
tweensilly2.Completed:Wait()
tweensilly3:Play()
tweensilly3.Completed:Wait()
tweensilly10:Play()
tweensilly10.Completed:Wait()
tweensilly5:Play()
tweensilly5.Completed:Wait()
tweensilly4:Play()
tweensilly4.Completed:Wait()
tweensilly6:Play()
tweensilly6.Completed:Wait()
tweensilly10:Play()
tweensilly10.Completed:Wait()
tweensilly7:Play()
tweensilly7.Completed:Wait()
tweensilly8:Play()
tweensilly8.Completed:Wait()
workspace.sillyguard.Position = Vector3.new(-674.891, 7.435, 771.918)
tweensilly9:Play()
tweensilly9.Completed:Wait()
end
workspace.sillyguard.Touched:Connect(function(character)
if debounce == true then
if character.Parent:FindFirstChild("Humanoid") then
if localplayer.Character and character:IsDescendantOf(localplayer.Character) then
debounce = false
print("touchi")
tweensilly1:Cancel()
tweensilly2:Cancel()
tweensilly3:Cancel()
tweensilly4:Cancel()
tweensilly5:Cancel()
tweensilly6:Cancel()
tweensilly7:Cancel()
tweensilly8:Cancel()
tweensilly9:Cancel()
tweensilly10:Cancel()
local goal3 = {}
goal3.CFrame = CFrame.lookAt(cam.CFrame.Position, workspace.sillyguard.Position)
local tweeninfo3 = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut)
local tween3 = tweenservice:Create(cam, tweeninfo3, goal3)
workspace.Camera.CameraType = Enum.CameraType.Scriptable
character.Parent.Humanoid.WalkSpeed = 0
local camera_ray = cam:ViewportPointToRay(viewport_size.X / 2,viewport_size.Y / 2)
workspace.sillyguard.CFrame = CFrame.lookAt(workspace.sillyguard.Position,camera_ray.Origin)
workspace.sillyguard.CFrame = workspace.sillyguard.CFrame:ToWorldSpace(CFrame.Angles(math.rad(90),0,0))
tween3:Play()
wait(0.75)
local goal2 = {}
goal2.Position = cam.CFrame.Position - Vector3.new(0,5,0)
local tweeninfo2 = TweenInfo.new(0.25, Enum.EasingStyle.Linear)
local tween2 = tweenservice:Create(workspace.sillyguard, tweeninfo2, goal2)
tween2:Play()
workspace.sillyguard.ghostboo:Play()
local camera_ray = cam:ViewportPointToRay(viewport_size.X / 2,viewport_size.Y / 2)
workspace.sillyguard.CFrame = CFrame.lookAt(workspace.sillyguard.Position,camera_ray.Origin)
workspace.sillyguard.CFrame = workspace.sillyguard.CFrame:ToWorldSpace(CFrame.Angles(math.rad(90),0,0))
wait(0.25)
workspace.sillyguard.ghostboo:Stop()
workspace.sillyguard.Orientation = Vector3.new(90, 90, 0)
workspace.sillyguard.Position = Vector3.new(-674.891, 7.435, 771.918)
workspace.Camera.CameraType = Enum.CameraType.Custom
character.Parent.Humanoid.WalkSpeed = 16
wait(1)
debounce = true
end
end
end
end)