How can I make a part have a Health attribute purely using code?
Asked by
4 years ago Edited 4 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
02 | local BossSpawn = Instance.new( "Part" , workspace) |
03 | BossSpawn.Size = Vector 3. new( 26.121 , 44.027 , 26.311 ) |
04 | BossSpawn.Position = Vector 3. new( 25 , 0 , 5 ) |
05 | BossSpawn.Color = Color 3. fromRGB( 0 , 0 , 0 ) |
06 | BossSpawn.Name = "Boss" |
11 | local Boss = game.Workspace:FindFirstChild( "Boss" ) |
12 | script.Parent.MouseButton 1 Click:Connect( function () |
13 | local SpawnBossAct = SpawnBoss() |
14 | SpawnBossAct.Touched:Connect( function () |
15 | local plr = game.Players.LocalPlayer |
16 | local character = plr.Character or plr.CharacterAdded:wait() |
17 | local humanoid = character:WaitForChild( "Humanoid" ) |
20 | local maxHp = humanoid.MaxHealth |
22 | humanoid.Health = maxHp - math.random( 20 , 60 ) |