Intro to Scripting: Make a Healing Potion
From Goodblox Wiki
Jump to navigationJump to search
This is an Basic, Brick related tutorial. |
Introduction
For now, this tutorial will show you how to make your brick heal your character when he touches it.
- Go to the start from your desktop, and click on GoodBlox studio.
- In GoodBlox Studio , go into "Edit mode".
- Select the brick you want to modify.
- Go to "Insert", then click object. Then type "Script" in the text box that comes up.
- Double-click the script, then a window should pop up.
- Remove all text inside the script, then type:
function onTouched(part) -- All characters have a Humanoid object -- If the model has one, it is a character local h = part.Parent:findFirstChild("Humanoid") -- Find Humanoids in whatever touched this if (h ~=nil) then -- If there is a Humanoid then h.Health = h.MaxHealth -- Set the health to maximum (full healing) end end script.Parent.Touched:connect(onTouched) -- Make it call onTouched when touched
This will not disappear when you touch it. If you want it to disappear, add script.Parent:remove()
below h.Health = h.MaxHealth
.
Advanced healing for VIPs
- This will mainly be good for a VIP room. This make their MAX health = 1000, and heals them to their maxhealth.
- Code
function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if (h ~=nil) then -- If there is a Humanoid then h.MaxHealth = 1000 h.Health = 1000 end end script.Parent.Touched:connect(onTouched)
Brick-Less Healing(One use)
- This is useful if you don't want people continuously healing.
bin = script.Parent Debounce = false function onButton1Down(mouse) local player = game.Players.LocalPlayer if player == nil then return end if (Debounce == false) then Debounce = true local h = player.Character:findFirstChild("Humanoid") mouse.Icon = "rbxasset://textures\\ArrowCursor.png" h.Health = h.Health + 50 --This is how much the player gets healed. end bin:Remove() end function onSelected(mouse) mouse.Icon = "rbxasset://textures\\ArrowCursor.png" mouse.Button1Down:connect(function() onButton1Down(mouse) end) end bin.Selected:connect(onSelected)
Just put it into a HopperBin.
Making a Spawning Health Pack
Make a Part and place this in it.
if script.Parent.className ~= "Part" then --Ensures that this is located within a part. script:Remove() end function onTouched(hit) --When activated: local h = hit.Parent:findFirstChild("Humanoid")--This searches for a humanoid in whatever it touched. if(h ~=nil)then --if a Humanoid tagged as "h" is found h.Health = h.MaxHealth--Sets the humanoid's max health, as it's health. script.Parent.Transparency = 1 --This makes said part visible. script.Parent.CanCollide = true --Makes said part solid. end end script.Parent.Touched:connect(onTouched) --Activates the "onTouched" function.