Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

SOLVED how would drain a player's health with one script? (it takes 2)

here is my code, it's in serverscriptservice. I have made this by myself. it works prefectly. You just need to tween the parts, that script is included

local player = game:GetService('Players').PlayerAdded:Connect(function(player)
local char = player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
	end)
end)

local function DamageOverTime()
local GasPart = game.Workspace.GasPart
repeat wait() hum.Health = hum.Health - 0.05
until
	GasPart.TouchEnded	
end			
	
for k,n in pairs(game.Workspace:GetChildren()) do
	local player = game:GetService('Players').PlayerAdded:Connect(function(player)
	local char = player.CharacterAdded:Connect(function(character)
			hum = character:WaitForChild("Humanoid")
	end)
end)
	local GasPart = game.Workspace.GasPart		
			
	if n.Name == "GasPart" then 
		
n.Touched:Connect(DamageOverTime) 

		end
end
	
	

another script in serverscriptservice.

local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(
		1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.InOut,
		-1,
		true,
		0	
	)

	local Goals = {
	Size = Vector3.new(11.56, 17.11, 27.11);
	}

for k,n in pairs(game.Workspace:GetChildren()) do
	
	if n.Name == "GasPart" then 	
		local exampletween = TweenService:Create(n, Info, Goals)
		exampletween:Play() 
	end
end

1 answer

Uhh The format is confusing me but I'll try to revise your script

game.Players.PlayerAdded:Connect(function(player) -- just put into a whole thread	
	local function DamageOverTime()
		playing = true
		local GasPart = game.Workspace.GasPart
		repeat -- you do not need the while wait() do
			wait(1)
			hum.Health = hum.Health - 1
		until hum.Health = 0 -- until hum.Died is invalid(i think)
		GasPart.TouchEnded:Connect(function() -- touchended is an event, why the if statement?
			print("the person has stopped touching me")
		end)
	end)
	for k,n in pairs(game.Workspace:GetChildren() do
		playing = false
		if n.Name == "GasPart" and playing == false then
			n.Touched:Connect(DamageOverTime)
		else
			print("nothing detected")
		end
	end
end)

Hope that helps

2 comments

1

that doesn't work.

0

oh rip sorry. im glad you figured it out tho.

This discussion is preserved as it was. New answers, comments, and votes are closed.