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

How can I make a part have a Health attribute purely using code?

Asked by 3 years ago
Edited 3 years ago

So, im trying to make a boss prototype for my game, but I cant figure out how to make the boss be able to take damage(Its a part spawned using an Instance.new function)

Here is the following script

function SpawnBoss()
    local BossSpawn = Instance.new("Part", workspace)
    BossSpawn.Size = Vector3.new(26.121, 44.027, 26.311)
    BossSpawn.Position = Vector3.new(25,0,5)
    BossSpawn.Color = Color3.fromRGB(0,0,0)
    BossSpawn.Name = "Boss"
    return SpawnBoss()  
end


local Boss = game.Workspace:FindFirstChild("Boss")
script.Parent.MouseButton1Click:Connect(function()
    local SpawnBossAct = SpawnBoss()
    SpawnBossAct.Touched:Connect(function()
        local plr = game.Players.LocalPlayer
        local character = plr.Character or plr.CharacterAdded:wait()
        local humanoid = character:WaitForChild("Humanoid")


        local maxHp = humanoid.MaxHealth

        humanoid.Health = maxHp - math.random(20,60)
        --I want to make it here so that when the player also touches the Boss, the boss takes damage but im not sure how to add health to the boss(Part)



    end)
end)


0
You're going to cause a stack overflow on line seven. Ziffixture 6913 — 3y

Answer this question