Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

1
that doesn't work. astonplep 32 — 3y
0
oh rip sorry. im glad you figured it out tho. Omq_ItzJasmin 666 — 3y
Ad

Answer this question