Hi, i am a fairly new Roblox scripting and i have been having some difficulty figuring out how to make a click multiplier when a player rebirths while also setting their clicks to zero and adding some coins to the players leaderstats. Here are the scripts:
Leaderstats:
local datastore = game:GetService("DataStoreService")
local data1 = datastore:GetDataStore("TapsData112")
local data5 = datastore:GetDataStore("RebirthsData112")
local data6 = datastore:GetDataStore("GemsData112")
local data8 = datastore:GetDataStore("GemiData112")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Clicks = Instance.new("IntValue", leaderstats)
Clicks.Name = "Clicks"
local Rebirths = Instance.new("IntValue", leaderstats)
Rebirths.Name = "Rebirths"
local Coins = Instance.new("IntValue", leaderstats)
Coins.Name = "Coins"
local Gemi = Instance.new("IntValue", leaderstats)
Gemi.Name = "Eggs"
Clicks.Value = data1:GetAsync(player.UserId) or 0
data1:SetAsync(player.UserId, Clicks.Value)
Rebirths.Value = data5:GetAsync(player.UserId) or 0
data5:SetAsync(player.UserId, Rebirths.Value)
Coins.Value = data6:GetAsync(player.UserId) or 0
data6:SetAsync(player.UserId, Coins.Value)
Gemi.Value = data8:GetAsync(player.UserId) or 0
data8:SetAsync(player.UserId, Gemi.Value)
game.Players.PlayerRemoving:Connect(function()
data1:SetAsync(player.UserId, Clicks.Value)
data5:SetAsync(player.UserId, Rebirths.Value)
data6:SetAsync(player.UserId, Coins.Value)
data8:SetAsync(player.UserId, Gemi.Value)
end)
end)
Buy RebirthScript
local suff = {'','K','M','B','T','qd','Qn','sx','Sp','O','N','de','Ud','DD','tdD','qdD','QnD','sxD','SpD','OcD','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT','INF'}
local function short(val) for i=1, #suff do if tonumber(val) < 10^(i*3) then return math.floor(val/((10^((i-1)*3))/100))/(100)..suff[i]end end end
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local leaderstats = player:WaitForChild("leaderstats")
local Clicks = leaderstats:WaitForChild("Clicks")
local Rebirths = leaderstats:WaitForChild("Rebirths")
local Gems = leaderstats:WaitForChild("Coins")
local MS = require(game.ServerStorage.Rebirths)
script.Parent.Buy.MouseButton1Click:Connect(function()
if Clicks.Value >= MS[script.Parent.Name]["C"]*(Rebirths.Value+1) then
Clicks.Value = 0
Rebirths.Value = Rebirths.Value + MS[script.Parent.Name]["R"]
Gems.Value = Gems.Value + MS[tostring(script.Parent.Name)]["R"]*10 * (leaderstats.Coins.Value)
end
end)
while wait() do
script.Parent.Title.Text = short(MS[script.Parent.Name]["R"]) .. " Rebirths for " .. short(MS[script.Parent.Name]["C"]*(Rebirths.Value+1)) .. " Clicks"
end
ClickScript (Event fired)
local debounce = false
function getMultiplier(Player, multiplierName)
local Multi = 0
for i,v in pairs(Player.Pets:GetChildren()) do
if v.Equipped.Value == true then
Multi = Multi + v[multiplierName].Value
end
end
return Multi
end
script.GetClick.OnServerEvent:Connect(function(plr)
if not debounce then
debounce = true
local leaderstats = plr:WaitForChild("leaderstats")
leaderstats.Clicks.Value = leaderstats.Clicks.Value + 2 + 2 * getMultiplier(plr, "Multiplier1", "Multiplier3")
wait(0.1)
debounce = false
end
end)
Im sorry if this is too much, but if someone can help me, it would be very much appreciated!

1 comment
You can condense the data into a table/array and use only 1 GetAsync and 1 SetAsync.