본문 바로가기
로블록스코드/로블록스 코드(초급)

로블록스 스튜디오 죽는 블록 코드

by 이은정 강사 2022. 2. 3.
반응형

로블록스에서 제일 많이 사용하는 블록중에 하나가 

캐릭터가 닿으면 죽는 블록입니다.

 

우선 간단하게 블록을 가지고 오는 방법으로는 도구상자를 가지고 오는 방법입니다.

 

 

2번째로는 스크립트를 이용해서 블록에 추가하는 방법

 

1) 부모의 휴머노이드 속성의 체력을 0으로 만들어버리는 방법

--Variables--
local Brick = script.Parent
--End--

--Code--
local function PlayerTouched(Part)
	local Parent = Part.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
		Parent.Humanoid.Health = 0
	end
end

Brick.Touched:connect(PlayerTouched)


2) 닿으면 지금의 체력에서 -100으로 빼는 방법입니다.

체력은 100이 최대값입니다.

function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if h~=nil then
		h.Health = h.Health -100

		wait(2.00)
	end
end

script.Parent.Touched:connect(onTouched)

 

반응형