CFrame going too fast?

Hello,

So I got a script here where there’s a trigger and when you touch it, the AI stops peeking behind the wall. The thing is, the movement is going faster than I’d like and I haven’t figured out why as I’m not really a scripter. I played around with the code for 5 mins, looked at possible threads relating to this, checked the API, still couldn’t find something useful. It doesn’t even look like it moved actually from how fast it goes, looks like it flat out disappeared.

Script:

local trigger = script.Parent.Parent.trigger
local holdpart = script.Parent.Parent.holdingpart
local Debounce = false
local model = script.Parent.Parent

trigger.Touched:Connect(function(hit)
	if not Debounce then
		if hit.Parent:FindFirstChild("Humanoid") then
			Debounce = true
			for i= 2, 2 do
				script.Parent.CFrame = script.Parent.CFrame * CFrame.new(2,0,0)
				wait()
			end
			for i= 2, 2 do
				script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,0)
				wait(2)
				Debounce = false
				script:Destroy()
			    model:Destroy()
		end
	end
end
end)

Video:

Easier explanation: The part I touched is the trigger, once it’s been touched the creature is made to move to the left hiding using the script I provided. The thing is, it hides too fast and not slow.

I’d appreciate anyone’s help/explanation on what’s causing this as I’d love to know!

I am not a scripter myself so I don’t know if this will help at all though, I’ve seen in other scripts where you can add a “wait” command and an amount of time so it doesn’t go away so fast. If you don’t know what I am talking about but think it might help, you can find how to add it in different tutorials and articles.

1 Like

Oh nevermind I didn’t see that you already added that…

you could use TweenService to create a smooth effect for the clown.

--top of script
local TweenService = game:GetService("TweenService")

--in the touched event
local clown = -- whatever the directory of the clown is, if its a model do its primary part
local tween = TweenService:Create(clown, TweenInfo.new(0.5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {CFrame = clown.CFrame * CFrame.new(4,0,0)})
tween:Play()

I hope this helps

1 Like