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:
RebirthGUI - Roblox
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:
Abbreviate - Roblox
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!
requirement - Roblox
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 !
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