ServerScriptService
에 Script
추가 Script
이름 PushingBlockScript
로 변경 PushingBlockScript
에 아래 코드 붙여넣기
-- Script by bean7189
-- 이 스크립트는 해당 위치에 있는 물체를 밀어내는 스크립트 입니다.
--// Service //--
local TweenService = game:GetService('TweenService')
----
--// Main //--
-- Workspace 내 모든 개체 탐색
for _, block: BasePart in pairs(workspace:GetDescendants()) do
-- 탐색한 개체가 BasePart가 아니면 다음 반복 수행
if not (block:IsA('BasePart')) then continue end
-- BasePart의 이름을 '-'로 분리하여 nameTable에 테이블 형태로 저장
local nameTable = string.split(block.Name, '-')
-- 이름 시작 부분이 'Block'이 아니면 다음 반복 수행
local isBlock = nameTable[1] == 'Block'
if not isBlock then continue end
-- 이름 중간 부분이 'Pushing'이 아니면 다음 반복 수행
local BlockType = nameTable[2]
if BlockType ~= 'Pushing' then continue end
-- Block-Pushing 파트 내에서 Pusher 파트 가져오기 (반드시 있어야 하므로 없으면 오류 유도)
local Pusher: BasePart = block:FindFirstChild('Pusher')
assert(Pusher)
-- Block-Pushing 파트 내에서 PushStart 파트 가져오기 (반드시 있어야 하므로 없으면 오류 유도)
local pushStart: BasePart = block:FindFirstChild('PushStart')
assert(pushStart)
-- Block-Pushing 파트 내에서 PushEnd 파트 가져오기 (반드시 있어야 하므로 없으면 오류 유도)
local pushEnd: BasePart = block:FindFirstChild('PushEnd')
assert(pushEnd)
-- Block-Pushing 파트 내에서 미리 설정한 PushTime 값 가져오기 (없으면 기본 값으로써 0.75초 적용)
local vPushTime: NumberValue = Pusher.Parent:FindFirstChild('PushTime')
local pushTime = (vPushTime and vPushTime.Value) and vPushTime.Value or 0.75
-- Block-Pushing 파트 내에서 미리 설정한 ReturnTime 값 가져오기 (없으면 기본 값으로써 1초 적용)
local vReturnTime: NumberValue = Pusher.Parent:FindFirstChild('ReturnTime')
local returnTime = (vReturnTime and vReturnTime.Value) and vReturnTime.Value or 1
-- Block-Pushing 파트 내에서 미리 설정한 WaitTime 값 가져오기 (없으면 기본 값으로써 5초 적용)
local vWaitTime: NumberValue = Pusher.Parent:FindFirstChild('WaitTime')
local waitTime = (vWaitTime and vWaitTime.Value) and vWaitTime.Value or 5
-- Pusher 파트 무게 제거
Pusher.Massless = true
-- PushStart 파트 투명화
pushStart.Transparency = 1
-- PushEnd 파트 투명화
pushEnd.Transparency = 1
-- Block-Pushing 파트와 Pusher 간 충돌 발생하지 않도록 설정
local NoCollisionConstraint = Instance.new('NoCollisionConstraint')
NoCollisionConstraint.Parent = block
NoCollisionConstraint.Part0 = block
NoCollisionConstraint.Part1 = Pusher
-- Pusher 파트가 PushStart 파트의 위치로 이동 되는 Tween 생성
local tweenPush = TweenService:Create(
Pusher,
TweenInfo.new(pushTime, Enum.EasingStyle.Linear),
{ Position = pushEnd.Position }
)
-- Pusher 파트가 PushEnd 파트의 위치로 이동 되는 Tween 생성
local tweenRetrun = TweenService:Create(
Pusher,
TweenInfo.new(returnTime, Enum.EasingStyle.Linear),
{ Position = pushStart.Position }
)
-- 별도 스레드에서
task.spawn(function()
-- 무한 반복문으로
while true do
-- Pusher 파트가 PushEnd 파트의 위치로 이동 되는 Tween 실행 및 완료 대기 (밀어내기)
tweenPush:Play()
tweenPush.Completed:Wait()
-- Pusher 파트가 PushStart 파트의 위치로 이동 되는 Tween 실행 및 완료 대기 (원위치)
tweenRetrun:Play()
tweenRetrun.Completed:Wait()
-- Pusher 파트가 다시 밀어내기 전까지 설정 시간 대기
task.wait(waitTime)
end
end)
end
----
Pusher: 물체를 밀어내는 파트
Block-Pushing: Pusher를 숨기고 있을 Pusher의 부모 파트
PushStart: Pusher가 물체를 밀어내기 전에 위치할 위치용 파트
PushEnd: Pusher가 물체를 완전히 밀어냈을 때 위치할 위치용 파트
PushTime: Pusher가 물체를 밀어내는 시간
RetrunTime: Pusher가 물체를 밀어내고 원위치하는 시간
WaitTime: Pusher가 물체를 밀어낸 후 다음 밀어내기까지 대기 시간