Hello, I am making a game called “Punching Simulator” and will be trying to make mechanics like Pull A Sword and Arm Wrestle Simulator. The problem is that I do not know how to make the mechanics such as, The fights, the data stores/leaderstats, the pets, and others.
Data Stores
Fights
Pets
Please help if you can help I will appreciate it greatly.
Bro i swear i was just in the Pull A Sword game a few minutes ago, anyways datastores are pretty easy, heres a basic datastore
local dss = game:GetService("DataStoreService") -- DataStoreService
local datastore = dss:GetDataStore("CoolDatastoreThing") -- Creates the datastore
game.Players.PlayerAdded:Connect(function(player)
local data
local folder = Instance.new("Folder") -- Creates a folder to store the values
folder.Name = "Values" -- Names the folder
folder.Parent = player -- Puts folder inside of the player
local examplevalue = Instance.new("NumberValue") -- Creates a value
examplevalue.Parent = folder
examplevalue.Name = "Example"
examplevalue.Value = 1
-- pcall is not needed, but I recommend using it to check if the value has loaded correctly or not
local yes, no = pcall(function()
data = datastore:SetAsync(player.UserId, examplevalue.Value) -- Loads the value
end)
-- Checks:
if yes then
print("Loaded value")
elseif no then
print("Cannot load value")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local yes, no = pcall(function()
datastore:SetAsync(player.UserId, player.Values.Example.Value)-- Saving the value
end)
-- Checks:
if yes then
print("Saved value")
elseif no then
print("Cannot save value")
end
end)
local datastore = dss:GetDataStore("testing") -- Creates the datastore
game.Players.PlayerAdded:Connect(function(player)
local data
local leaderstats = Instance.new("Folder") -- Creates a folder to store the values
leaderstats.Name = "leaderstats" -- Names the folder
leaderstats.Parent = player -- Puts folder inside of the player
local Wins = Instance.new("NumberValue") -- Creates a value
Wins.Parent = leaderstats
Wins.Name = "Wins"
Wins.Value = 0
local Strength = Instance.new("NumberValue") -- Creates a value
Strength.Parent = leaderstats
Strength.Name = "Strength"
Strength.Value = 0
local Rebirths = Instance.new("NumberValue") -- Creates a value
Rebirths.Parent = leaderstats
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
-- pcall is not needed, but I recommend using it to check if the value has loaded correctly or not
local yes, no = pcall(function()
data = datastore:SetAsync(player.UserId, Wins.Value, Strength.Value, Rebirths.Value) -- Loads the value
end)
-- Checks:
if yes then
print("Loaded value")
elseif no then
print("Cannot load value")
wait(5)
player:Kick("Error Loading Data")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local yes, no = pcall(function()
datastore:SetAsync(player.UserId, player.leaderstats.Wins.Value, player.leaderstats.Strength.Value, player.leaderstats.Rebirths.Value)-- Saving the value
end)
-- Checks:
if yes then
print("Saved value")
elseif no then
print("Cannot save value")
end
end)