I currently have a sword fighting game, How would i make it where every minute or two a health potion will fall from the sky, picking it up will allow you to heal yourself to full HP after consuming it, and may only be used once?
For the health potion falling from the sky, you can use a loop, Clone(), math.random, and CanCollide = false to make the health potion fall randomly. To pick the health potion up, you can use Click Detector, Proximity Prompts, touch events, etc. and add it to the player’s backpack. To give the player HP when consumed, you can use the Tool.Activated function and increase the player’s health using, Humanoid.Health. Then you can use Tool:Destory() to remove the tool from the game.
This is just one method, and I believe there are other ways. This method just came to my head. I hope this helps.
The most simple approach as @ardrous mentioned is creating a loop which sends a Health Potion to the sky every minute, you can use this a couple of ways but the more common usage is by using a while true do/while wait(60) do loop
Next you’d want to define where your Health Potion is going to be, preferably inside ServerStorage to keep it secure that way
Inside your loop, you’d want to create a clone of the Potion using the Clone() function (Keep in mind though that this is a Tool object, you’d need to reference the Tool’s Handle in order to randomly position it)
local HealthPotion = game.ServerStorage:WaitForChild("HealthPotion")
while wait(60) do
local RandomPosition = Vector3.new(math.random(-75, 75), 50, math.random(-75, 75))
local Clone = HealthPotion:Clone()
Clone.Parent = workspace
Clone.Position = RandomPosition
end
You could use the Health Potion that ROBLOX provides or you can create your own, as long as you know how to handle Tool Events
THANK YOU SO MUCH!! big help have a good one