Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could i add a click multiplyier when a player rebirth's?

Asked by 3 years ago

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!

0
You can condense the data into a table/array and use only 1 GetAsync and 1 SetAsync. Dovydas1118 1495 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

You could add an argument called rebirths to the function getMultiplier and when you call the function just add the amount of rebirths the player has by adding Rebirths.Value as the rebirths argument and then change the Multi to rebirths. Like this:

    function getMultiplier(Player, multiplierName, rebirths)
        local Multi = rebirths
        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

Call the function like this getMultiplier(plr, "Multiplier1", "Multiplier3", Rebirths.Value). I dont know why is there one argument multiplierName and you gave it two arguments.

0
Where would i put this script, should i put it in a script or in a new script, and i had added "Multiplier3" to the script because i tried to fix this but it didn't work but when i removed the things i forgot to remove that. cookie0609life 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I found where to put the script, but it doesn't work, it says this:

W001: Unknown global "Rebirths"

This is my script now:

local debounce = false

function getMultiplier(Player, multiplierName, rebirths)
    local Multi = rebirths
    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", Rebirths.Value)
        wait(0.1)
        debounce = false
    end
end)

It would be amazing if you could continue helping me!

0
I thought it's in the same script, my bad. Since it's a different script all you gotta do is import the database and store the rebirths value in a variable. Import it: local datastore = game:GetService("DataStoreService") Store it in a var: local Rebirths= datastore:GetDataStore("RebirthsData112") Thats it, just add it on the top of the I just commented on. dinko13579 35 — 3y

Answer this question