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

How would I create a set number of lives before a it restarts at the beginning spawn?

I am making an OBBY with checkpoints and have no idea where to start on how to create a set number of lives which on the last life sets them back at the starting point with a game over. If anyone could help me it would be greatly appreciated. Thank You!

2 comments

0

Just to clarify I am not looking for someone to write my script just a point in the general direction would be nice

0

There are multiple ways to do this. One method would be to just use an IntValue object as a count down, if it reaches 0 reset the player.

3 answers

✓ Accepted answer

Honestly, the easiest way, in my opinion, is to use an IntValue. I'm not sure how you're figuring what stage they're on, whether it be using spawns with different teams (the old fashioned way) or using a stage system with a leaderboard. Nevertheless, it should be a relatively simple thing to do. (As per your request, i'll refrain from coding anything for you, but I'll provide wiki links for all of the concepts I mention, in case you're unfamiliar with anything)

First, when the player enters the game, create an IntValue in the player, which is relatively simple. Then simply create an event that when the player's humanoid dies, it will subtract a "life" from the value you created.

From there, simply create a script that triggers everytime the value is changed. Check to see if the value is at zero. If so, you can set the player's stage back to the beginning, whether that be by changing their team or changing their leaderstat value.

Also, because I have a good eye for seeing places to earn some robux, this system would be very easy to implement a "Buy more lives" developer product(s). In essence, you can easily add to the value however many lives they purchase.

I hope this helps, I can answer any questions you may have either via ROBLOX PM or by the comment section of my answer.

Good luck!

Wiki Links (For Convenience):

Developer Products (Just in case you decide to try it)

Humanoid Died Function

Value Changed

Instance.new

PlayerAdded

1 comment

0

So I was able to get my lives, stages and a timer even added in. My problem now is I am having problems getting it to lose a value on lives each time I die even with the wiki. Also when I try to add in to the script it removes the timer and stage from showing during game play.

While I was going to just type a small comment, I'll just give a basic answer explaining.

First we're going to start with getting the services you'll need.

-- || Services || --
local Players = game:GetService("Players")

Let's get the event: .PlayerAdded() on Players' Service!

-- || Services || --
local Players = game:GetService("Players")

-- || PlayerAddedEvent || --
Players.PlayerAdded:connect(function(Player) -- This'll be a variable connected to that joined Player.
end)

Now you can do just about anything with the Player that joins!

-- || Services || --
local Players = game:GetService("Players")

-- || PlayerAddedEvent || --
Players.PlayerAdded:connect(function(Player)
	print(Player.Name) -- This'll print the Player's name into the Output.
end)

Now you're wanting stuff like leaderboards and such, let's give you basic stuff... We don't want to spoil the fun of learning for ya eh?

We're going to do so with something called a function; functions allow for programmers(scripters) to reuse code, stuff like ModuleScripts and BindableEvents/Functions work the similar, but allow multiple scripts to use those functions.

-- || Services || --
local Players = game:GetService("Players")

-- || CreateLeaderboard || --
local function CreateLeaderboard(Parent) -- This will be the variables it uses.
	local Leaderboard = Instance.new("Folder", Parent) --  You can use Model, IntValue and Folder to contain this.
	Leaderboard.Name = "leaderstats" -- EDIT: Not 100% sure if leaderboard or leaderstats... Hopefully it'll work between one of the two. (I'd check if my internet here wasn't blocking Roblox API. (Lol)
	
	local Lives = Instance.new("NumberValue", Leaderboard)
	Lives.Name = "Lives"
	
	local Stage = Instance.new("NumberValue", Leaderboard) 
	Stage.Name = "Stage"

end

-- || PlayersAddedEvent || --
Players.PlayerAdded:connect(function(Player)
	print(Player.Name) 
	CreateLeaderboard(Player) -- Variable `Parent` will be Player for this cycle.
end)

There you go, you have your Leaderboard, now you'll have to do the rest on your own. But I'll give you the resources you'll need!

Player.CharacterAdded:connect(function(Character) --[[ Code here --]] end)

Humanoid

Best of luck! Hope I helped!

game.Players.PlayerAdded:connect(function(plr)
	local Stats = Instance.new('IntValue', plr)
	Stats.Name = 'leaderstats'
	
	local Lives = Instance.new('IntValue', Stats)
	Lives.Name = 'Lives'
	Lives.Value = 25
	
	local Stage = Instance.new('IntValue', Stats)
	Stage.Name = 'Stage'
	Stage.Value = 1
	
	local Timer = Instance.new('IntValue', Stats)
	Timer.Name = 'Time'
	Timer.Value = 0
	while true do
		wait(1)
		Timer.Value = Timer.Value +1
	end end)

This is what I have so far but it isn't letting me change the lives upon death. I followed the wiki but nothing happened except it stopped showing the stage and timer. Which seems to happen every time I try to edit the lives section.

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