I am trying to make a wall pusher for a project I am working on called Trapped but I am stuck at the wall push script now I have been to other Developers and they could not help so now I am here.
I want to make a brick move in and out since the trap is meant to push you into lava and you meant to doge it.
Hope someone can help me.
Letting you know I am a Noobie at scripting, just trying to learn it.
You’re probably looking for a while loop making it constantly run, then you could use CFrame, or TweenService.
Example of CFrame:
while wait(3) do
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, 0.1, 0) --You can change the value here to change how the block expands.
wait()
end
Example of Tween:
-- Locals --
local model = workspace.Model
local door1 = model.Door1:GetChildren()
local keycardHolder = model:GetChildren(model.KeyCardHolder)
-- Info's --
local tweenInfor = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
model.KeyCardHolder.Touched:Connect(function(tch)
if tch.Parent.Name == "L-4 Clearance" then
print("door opened")
for i , v in pairs(door1) do
local myTabla = {Position = Vector3.new((v.Position.X + (v.Size.X * -1)),v.Position.Y,v.Position.Z)}
local tween = TweenService:Create(v, tweenInfor, myTabla)
tween:Play()
end
end
end)
Bear in mind, the code above is just an example and I made it a long time ago.
I would use the TweenService to do that, as we can easily add a debounce and we can add delays in a lot easier.
To do this we will use the while loop and we will have a non-collide part that has a transparency of 0, that demonstrates where the push block is going to “go”.
This is what the script would look like if we use the TweenService;
local TweenService = game:GetService("TweenService")
local pushblock = script.Parent
local info = TweenInfo.new(
5 --How fast you want the animation to last
Enum.EasingStyle.Linear --The way it is tweened, would keep it at Linear for your case
Enum.EasingDirection.Out --The direction the tween is animating the part, keep it out
0 --Amount of times tween repeats (set to 0, due to use of while loop instead
true --reverses the tween, set it to true so that the block goes back
0 --Interval between repeats, set to 0 because we are not using a repeat
)
That is the tweening information now we will set the goal of the tween and what exactly the tween will do.
local InvisiblePart = workspace.NONCOLLIDEPART
local newtween = TweenService:Create(pushblock, info, {CFrame = InvisiblePart.CFrame} )
Good, now we have to play the tween, if you want to play the tween continuously with/without a delay you can use this code:
while true do --this will make it loop through the specified code infinite times, keep in mind so that the script doesn't crash the game we must add in a wait, which will act as the delay between tweens.
wait(7) --time before animation starts up again
newtween:Play()
end