Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Anyone can help my make a coin that gives 10 extra max health?

i don't know how to get the player that touched the coin pls help

2 answers

100 health is automatic set I don't think you can give more than 100. Unless if the player is already harmed. Though you could change how much health something takes.

2 comments

0

There is a property in the Humanoid called 'MaxHealth'

0

Oh I didn't know that


Please note that this isn't a website to be asking for scripts/code.


Anyways it's fairly simple to make this type of script, first of all make sure to have a server script in Workspace or ServerScriptService and not a module/local script, then have a part in Workspace that will work as a coin.

local coin = game.Workspace.Coin -- The coin that will give +10 extra hp.
local debounce = false -- Making a debounce so that the coin function doesn't fire too many times. (Cooldown)
local debounceTime = 5 -- Time for the debounce (seconds), can be changed.
	
coin.Touched:Connect(function(hit) -- Function that fires every time the coin gets touched.
		
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then -- If the object that touched the coin has a Humanoid in it the block of code will run.
		local humanoid = hit.Parent:FindFirstChild("Humanoid") -- Making the humanoid a variable.
		debounce = true -- Starting the cooldown
		
		humanoid.MaxHealth = humanoid.MaxHealth + 10 -- Giving the Humanoid's max health + 10 health
		
		wait(debounceTime) -- The amount of time this block of code can be run again.
		debounce = false -- After the debounce time has ran out the debounce has been set to false meaning this block of code can be run again.
	end
		
end)

2 comments

0

A very well explained script however with 1 slight misunderstanding, if the humands health is not 100 and it adds 10, in theory you will be giving more health to the humaoind to solve this on line 11 you have to do some arithmetic such as Humanoid.MaxHealth-Humanoid.Health and then use operators to check if that value is greater than 10 and if so just add 10 to health and if not subract it from 1

0

*and if not subtract it from 10 and add that to the humanoid's maxhealth

This discussion is preserved as it was. New answers, comments, and votes are closed.