How to Script Some Game Essentials

Warning: This is my first topic on Community Tutorials

Have you ever wondered on how to make a game in less then an hour then this is the topic for you!

In this topic you will learn on how to make a speed simulator game in less then an hour!
just for a tutorial
lets start!

Stats

Before we start we have to know what datastore we are gonna use for example im going to use DataStore2!

first of all we have to publish the game and turn on api services

[DATASTORE 2]
first we need to combine the keys!

lets do it!

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- combine
DataModule.Combine("NewDataKey", "Speed", "Rebirths")

great now that it is done lets make the datastore variables!

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- combine
DataModule.Combine("NewDataKey", "Speed", "Rebirths")

-- function
function PlayerAdded(Player)
	-- datastores
	local SpeedStore = DataModule("Speed", Player)
	local RebirthsStore = DataModule("Rebirths", Player)
end

for the last step we need to make the values and leaderstats etc etc.

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- combine
DataModule.Combine("NewDataKey", "Speed", "Rebirths")

-- function
function PlayerAdded(Player)
	-- datastores
	local SpeedStore = DataModule("Speed", Player)
	local RebirthsStore = DataModule("Rebirths", Player)
	
	-- stats
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "leaderstats"
	StatsFolder.Parent = Player
	
	-- values
	local Speed = Instance.new("NumberValue")
	Speed.Name = "Speed"
	Speed.Value = SpeedStore:Get(1)
	Speed.Parent = StatsFolder
	
	SpeedStore:OnUpdate(function(Value)
		Speed.Value = Value
	end)
	
	local Rebirths = Instance.new("NumberValue")
	Rebirths.Name = "Rebirths"
	Rebirths.Value = RebirthsStore:Get(0)
	Rebirths.Parent = StatsFolder
	
	RebirthsStore:OnUpdate(function(Value)
		Rebirths.Value = Value
	end)
	
	local Debounce = Instance.new("BoolValue", game.ServerStorage.DebounceValues)
	Debounce.Name = Player.Name
	Debounce.Value = false
end

now that is done the final step for the leaderstats is setting the players’s speed and make the function work!

now here is the full code!

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- combine
DataModule.Combine("NewDataKey", "Speed", "Rebirths")

-- function
function PlayerAdded(Player)
	-- datastores
	local SpeedStore = DataModule("Speed", Player)
	local RebirthsStore = DataModule("Rebirths", Player)
	
	-- stats
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "leaderstats"
	StatsFolder.Parent = Player
	
	-- values
	local Speed = Instance.new("NumberValue")
	Speed.Name = "Speed"
	Speed.Value = SpeedStore:Get(1)
	Speed.Parent = StatsFolder
	
	SpeedStore:OnUpdate(function(Value)
		Speed.Value = Value
	end)
	
	local Rebirths = Instance.new("NumberValue")
	Rebirths.Name = "Rebirths"
	Rebirths.Value = RebirthsStore:Get(0)
	Rebirths.Parent = StatsFolder
	
	RebirthsStore:OnUpdate(function(Value)
		Rebirths.Value = Value
	end)
	
	local Debounce = Instance.new("BoolValue", game.ServerStorage.DebounceValues)
	Debounce.Name = Player.Name
	Debounce.Value = false
	
	local Character = Player.Character
	local Humanoid = Character.Humanoid
	
	Humanoid.WalkSpeed = SpeedStore:Get(0) / 5 * 3.12
end

-- call functions
game.Players.PlayerAdded:Connect(PlayerAdded)

for _, Player in pairs(game.Players:GetPlayers()) do
	PlayerAdded(Player)
end
Add Points!

Now that we are done with the leaderstats lets do the add points

For Example:
Each Activation We make with the tool we are gonna activate it to the server and add the values up there so no exploiting!

First of which we need to make a script in ServerScriptService called ServerHandler

After you made it will look like this:

http://myprintscreen.com/s/1kouy/8ad3b950a2

Now we are gonna add a Folder in ReplicatedStorage called Events and After that it Should look like this:

http://myprintscreen.com/s/1kov0/53647c39e2

After that put 1 remote event and 1 remote function!
Name the RemoteEvent: AddPoints
Name the RemoteFunction: Rebirth

and after that it should look like this:

http://myprintscreen.com/s/1kov3/d7f5083e48

so now after that lets get straight to the coding!

first of which we need a tool get any tool!
then after that put 1 local script and Name it Client

and also put a module in the tool and name it AddPointsModule

next of which is writing the code we will do the local script first!

first we need to define the module and the tool

lets code it here:

-- tool
local Tool = script.Parent

-- module
local Module = require(Tool:WaitForChild("AddPointsModule"))

now after getting the variables we need to fire the function of the module

here is the code:

-- tool
local Tool = script.Parent

-- module
local Module = require(Tool:WaitForChild("AddPointsModule"))

Tool.Activated:Connect(function()
	Module.AddPoints()
end)

Lets get straight to the Module!

first of all we need the remote events and the remote functions
it is important to have it or else it would error and before you write the code [MAKE SURE TO MAKE THE OBJECTS BEFORE CODING IT THANKS!]

the code should be like this:

local module = {}

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints

return module

now fire the server with no arguments:

local module = {}

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints

module.AddPoints = function()
	AddPoints:FireServer()
end

return module

The Server:
Now that we passed nothing in arguments lets go back to the ServerHandler Script!

First of all we need all variables we need,

the code should be like this

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- debounce
local DebounceValues = game.ServerStorage.DebounceValues

also if you havent already made a folder in serverstorage named DebounceValues make sure to make it or else it wont work!

it should look like this after adding it:
http://myprintscreen.com/s/1kovc/48d4d1ed4f

now we go on adding the event connection,

the code should look like this

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- debounce
local DebounceValues = game.ServerStorage.DebounceValues

-- events basically
AddPoints.OnServerEvent:Connect(function(Player)
    -- test this is not included in the code but ok
end)

and you maybe wondering why did you not pass any argument on the client and have player as the parameter on the Server?

Answer: if you fire anything on the client you the client is the one who fired it so you dont need to add it as an argument only as the parameter in the server!

now we add debounce,

the code should look like this

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- debounce
local DebounceValues = game.ServerStorage.DebounceValues

-- events basically
AddPoints.OnServerEvent:Connect(function(Player)
	-- to check if its false and the player exists
	if not DebounceValues[Player.Name].Value and Player then
		DebounceValues[Player.Name].Value = true
        wait(1)
		DebounceValues[Player.Name].Value = false
    end
end

for the final add points we need to add the option of checking if they have any rebirths if they have multiply it by the times of rebirth values like RebirthValue * 5000 then change walkspeed with our own speed calculation

the code:

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- debounce
local DebounceValues = game.ServerStorage.DebounceValues

-- events basically
AddPoints.OnServerEvent:Connect(function(Player)
	-- to check if its false and the player exists
	if not DebounceValues[Player.Name].Value and Player then
		DebounceValues[Player.Name].Value = true
		-- handling and adding
		-- datastores
		local SpeedStore = DataModule("Speed", Player)
		local RebirthsStore = DataModule("Rebirths", Player)
		
		if RebirthsStore:Get(0) > 0 then
			SpeedStore:Increment(10 * RebirthsStore:Get(0) * 2)
		else
			-- if 0 or -1
			SpeedStore:Increment(1)
		end
		
		local Character = Player.Character
		local Humanoid = Character.Humanoid
		
		Humanoid.WalkSpeed = SpeedStore:Get(0) / 5 * 3.12
		
		wait(1)
		DebounceValues[Player.Name].Value = false
	end
end)

Rebirths

now that is done, we now have to code a ui don’t worry ill leave the ui link here:
https://www.roblox.com/library/5635429365/RebirthGUI

now thats done we have to go to the main core local script and you will see that every variable has been set up for you which means you only need to code it!

now lets start the coding,

First we need the rebirth button to tween the ui position and play a sound:
the code should look like this after coding it,

-- Main Core: FerbZides

-- Stats
local Player = game.Players.LocalPlayer

-- abbreviate it
local AbbreviationModule = require(game.ReplicatedStorage.AbbreviationModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- Gui Objects
local Gui = script.Parent
local RebirthFrame = Gui.Background
local ExitButton = RebirthFrame.Exit
local RebirthButton = RebirthFrame.Rebirth
local Warning = RebirthFrame.Warning
local MainButton = Gui.Rebirth

-- sound objects
local Sound = script.Click

-- Positions
local InPosition = UDim2.new(.583, 0, .543, 0)
local OutPosition = UDim2.new(-1.1, 0, .526, 0)

-- Scripting
MainButton.MouseButton1Click:Connect(function()
	RebirthFrame.Visible = true
	RebirthFrame:TweenPosition(InPosition, "In", "Quad", .5, false)
	Sound:Play()
end)

now thats done we have to make the exit opposite of the main button,
the code should look like this after coding it:

-- Main Core: FerbZides

-- Stats
local Player = game.Players.LocalPlayer

-- abbreviate it
local AbbreviationModule = require(game.ReplicatedStorage.AbbreviationModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- Gui Objects
local Gui = script.Parent
local RebirthFrame = Gui.Background
local ExitButton = RebirthFrame.Exit
local RebirthButton = RebirthFrame.Rebirth
local Warning = RebirthFrame.Warning
local MainButton = Gui.Rebirth

-- sound objects
local Sound = script.Click

-- Positions
local InPosition = UDim2.new(.583, 0, .543, 0)
local OutPosition = UDim2.new(-1.1, 0, .526, 0)

-- Scripting
MainButton.MouseButton1Click:Connect(function()
	RebirthFrame.Visible = true
	RebirthFrame:TweenPosition(InPosition, "In", "Quad", .5, false)
	Sound:Play()
end)

ExitButton.MouseButton1Click:Connect(function()
	RebirthFrame:TweenPosition(OutPosition, "In", "Quad", .5 , false)
	Sound:Play()
end)

Last part of the client and full code of the client,
we now have to code of sending info on the server,
the code should look like this after coding it:

-- Main Core: FerbZides

-- Stats
local Player = game.Players.LocalPlayer

-- abbreviate it
local AbbreviationModule = require(game.ReplicatedStorage.AbbreviationModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- Gui Objects
local Gui = script.Parent
local RebirthFrame = Gui.Background
local ExitButton = RebirthFrame.Exit
local RebirthButton = RebirthFrame.Rebirth
local Warning = RebirthFrame.Warning
local MainButton = Gui.Rebirth

-- sound objects
local Sound = script.Click

-- Positions
local InPosition = UDim2.new(.583, 0, .543, 0)
local OutPosition = UDim2.new(-1.1, 0, .526, 0)

-- Scripting
MainButton.MouseButton1Click:Connect(function()
	RebirthFrame.Visible = true
	RebirthFrame:TweenPosition(InPosition, "In", "Quad", .5, false)
	Sound:Play()
end)

ExitButton.MouseButton1Click:Connect(function()
	RebirthFrame:TweenPosition(OutPosition, "In", "Quad", .5 , false)
	Sound:Play()
end)

RebirthButton.MouseButton1Click:Connect(function()
	local Signal = RebirthEvent:InvokeServer()
	
	if Signal == true then
		Warning.Text = "Successfully Rebirthed!"
		wait(1)
		if Player.leaderstats.Rebirths.Value * 5000 > 0 then
			Warning.Text = "You need atleast "..AbbreviationModule:Abbreviate(Player.leaderstats.Rebirths.Value * 5000).." Speed to Rebirth!"
		else
			Warning.Text = "You need atleast "..AbbreviationModule:Abbreviate(5000).." Speed to Rebirth!"
		end
		wait(1)
		RebirthFrame.Visible = false
	elseif Signal == false then
		Warning.Text = "Failed to Rebirth!"
		wait(1)
		if Player.leaderstats.Rebirths.Value * 5000 > 0 then
			Warning.Text = "You need atleast "..AbbreviationModule:Abbreviate(Player.leaderstats.Rebirths.Value * 5000).." Speed to Rebirth!"
		else
			Warning.Text = "You need atleast "..AbbreviationModule:Abbreviate(5000).." Speed to Rebirth!"
		end
		wait(1)
		RebirthFrame.Visible = false
	end
end)

what this means is that it will send a signal on the server and the server returns info on the client and the client checks if its false or true

[IMPORTANT]
Before we continue on the server make sure to add an abbreviation module:
https://www.roblox.com/library/5642404615/Abbreviate

then put it in ReplicatedStorage and after that it should look like this:
http://myprintscreen.com/s/1kpmc/130f9a2349

The Server:

Now we need our datastore2 variables and other stuff,
let’s code it!

The code should look like this after:

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- debounce
local DebounceValues = game.ServerStorage.DebounceValues

-- events basically
AddPoints.OnServerEvent:Connect(function(Player)
	-- to check if its false and the player exists
	if not DebounceValues[Player.Name].Value and Player then
		DebounceValues[Player.Name].Value = true
		-- handling and adding
		-- datastores
		local SpeedStore = DataModule("Speed", Player)
		local RebirthsStore = DataModule("Rebirths", Player)
		
		if RebirthsStore:Get(0) > 0 then
			SpeedStore:Increment(10 * RebirthsStore:Get(0) * 2)
		else
			-- if 0 or -1
			SpeedStore:Increment(1)
		end
		
		local Character = Player.Character
		local Humanoid = Character.Humanoid
		
		Humanoid.WalkSpeed = SpeedStore:Get(0) / 5 * 3.12
		
		wait(1)
		DebounceValues[Player.Name].Value = false
	end
end)

RebirthEvent.OnServerInvoke = function(Player)
	-- datastores
	local SpeedStore = DataModule("Speed", Player)
	local RebirthsStore = DataModule("Rebirths", Player)
end)	

Now we need to add if statements to check if they have enough value to rebirth,

The code should look like this after coding it:

-- Module
local DataModule = require(game.ServerStorage.MainModule)

-- event
local ReplicatedStorage = game.ReplicatedStorage
local EventsFolder = ReplicatedStorage.Events
local AddPoints = EventsFolder.AddPoints
local RebirthEvent = EventsFolder.Rebirth
local ChangeSpeed = EventsFolder.ChangeSpeed

-- debounce
local DebounceValues = game.ServerStorage.DebounceValues

-- events basically
AddPoints.OnServerEvent:Connect(function(Player)
	-- to check if its false and the player exists
	if not DebounceValues[Player.Name].Value and Player then
		DebounceValues[Player.Name].Value = true
		-- handling and adding
		-- datastores
		local SpeedStore = DataModule("Speed", Player)
		local RebirthsStore = DataModule("Rebirths", Player)
		
		if RebirthsStore:Get(0) > 0 then
			SpeedStore:Increment(10 * RebirthsStore:Get(0) * 2)
		else
			-- if 0 or -1
			SpeedStore:Increment(1)
		end
		
		local Character = Player.Character
		local Humanoid = Character.Humanoid
		
		Humanoid.WalkSpeed = SpeedStore:Get(0) / 5 * 3.12
		
		wait(1)
		DebounceValues[Player.Name].Value = false
	end
end)

RebirthEvent.OnServerInvoke = function(Player)
	-- datastores
	local SpeedStore = DataModule("Speed", Player)
	local RebirthsStore = DataModule("Rebirths", Player)
	
	if RebirthsStore:Get(0) * 5000 > 0 then
		if SpeedStore:Get(0) > RebirthsStore:Get(0) * 5000 then
			SpeedStore:Set(0)
			RebirthsStore:Increment(1)
			local Character = Player.Character
			local Humanoid = Character.Humanoid
			
			Humanoid.WalkSpeed = SpeedStore:Get(0) / 5 * 3.12
			return true
		else
			return false
		end
	else
		if SpeedStore:Get(0) > 5000 then
			SpeedStore:Set(0)
			RebirthsStore:Increment(1)
			local Character = Player.Character
			local Humanoid = Character.Humanoid
			
			Humanoid.WalkSpeed = SpeedStore:Get(0) / 5 * 3.12
			return true
		else
			return false
		end
	end
end

it checks if they have enough rebirths and if they have rebirths we will multiply it by 5000 the default speed requirement for a rebirth!

Part Requirement

This is an extra category, if you need anything else

if you need a rebirth or speed part requirement we need to code it!

first we will get the part link get it here below!
https://www.roblox.com/library/5642415015/requirement

Last thing is put it in workspace and change the text labels text and the value needed to enter the part

Thats it your done and goodluck with your game!

Extra Stuff

This is just for my video showing that i am fixing the game and stuff

here is the link to watch it btw:
https://www.youtube.com/watch?v=-0k2W7aI_WM

Also if you have extra time make sure to like and subscribe to my Channel :slight_smile:!

Benefits

This would improve your scripting skills and probably have knowledge on datastores probably well since its datastore2 so yeah

If you have any questions you can just reply below this topic or pm me!

Thanks,
FerbZides

25 Likes

I personally think this resource is promoting a bad practice in making games. Developing games should be done carefully with proper planning, implementation, code base etc. and not within an hour unless it’s one of those development jokes/challenges where people make games within a very small time frame.

20 Likes

i understand it is just a basic tutorial not for a real game

1 Like

In addition to what is said above, the title is misleading. You should consider changing it to something along the lines of “How to Script Some Game Essentials”, as making a whole game implies that there is something that can be played once the tutorial is completed, while this is not.

3 Likes

In my opinion, this is more of a quick cash grab project, which doesn’t really help Roblox at all.

2 Likes

sorry if this is a negative topic its my first time posting in community tutorials

2 Likes

Don’t worry, we can tell your motives weren’t negative, you were trying to help, and you probably will help many people.

3 Likes

Hmm, I don’t think that this is very encouraging, especially for newer developers. It would be nicer if you explained it more in depth and sounds more of a dare sort of thing. You do you, just consider how it’s going to help the community and what people can take from it. No need to be sorry about it being a negative topic, I don’t see how it’s.

2 Likes

I think there needs to be more like this

As a new developer, I need to start understanding scripting to further develop as my games as I can already build and make graphics.

I’m going to try and make this game, thank you!.

2 Likes

I did not understand DS2 at all, I atleast gained a lil’ knowledge!

1 Like

This is my first time replying in devfourm. I just wanted to say your tutorial was excellent for me.

1 Like

By the way, I would highly recommend agaisn’t the use of DataStore2 for now.

DataStore2 just handles player data for you. You load what you want and it gets everything and blah blah blah. DS2 will also keep backups, but they can be sometimes problematic.

I would just say, forget about DS2 for now. There’s a datastore update coming which will have backups available to the developer and it’s pretty great.

If you want something as “cool” as DS2, ProfileService should be really good. It also deals with player data pretty well.

Even Kampfkarren has talked about the “OrderedBackups” method not being that good because it can cause some problems.

this was a long time ago I was actually using DataStore2 for my games but now I am using ProfileService

1 Like

I dont think teaching how to script is not so effective you gotta do practices and have ability alghorythmic thinking so you can turn your “alghorytm” into a “code”

this might be useful for some people who want to just make a simple game but in the long run their game code is not even gonna come from this source

2 Likes

Yup but create your own code always is my preferance, it can be simple or not.

1 Like

Don’t worry man. It’s your first post in #resources:community-tutorials. Take the feedback and criticism from these comments and make an improved or better version next time. :smiley:

2 Likes