I need help making a Upgrading System, I can’t figure out the issue so I am creating this post.
The issue is that the upgrades don’t work how they should, it should upgrade once every time u click it. But if there are multiple players in the server it upgrades the amount of players in the server so if there are 2 ppl in the server it upgrades twice and so on.
Client:
-- Variables
local plr = game:GetService("Players").LocalPlayer
-- Dictionaries
local Settings = {
MultiplierCap = 100,
GemMultiplierCap = 6
}
local PlrStats = {
MultiLevel = plr:WaitForChild("ValueFolder").MultiLevel,
Multiplier = plr:WaitForChild("ValueFolder").Multiplier,
GemsLevel = plr:WaitForChild("ValueFolder").GemsLevel,
GemsMulti = plr:WaitForChild("ValueFolder").GemsMulti,
Gemstones = plr:WaitForChild("ValueFolder").Gemstones
}
local abbreviationss = {
"";
"k";
"m";
"b";
"t";
"qd";
"qi";
"sx";
"sp";
"oc";
"no";
"dc";
"ud";
"dd";
"dD";
"td";
"qad";
"qid";
"sxd";
"spd";
"ocd";
"nod";
"vg";
"uvg"
}
local function abbreviate(val)
for i=1, #abbreviationss do
if tonumber(val) < 10^(i*3) then
return math.floor(val/((10^((i-1)*3))/100))/(100)..abbreviationss[i]
end
end
end
local PriceTable = {
12256, 14946, 25765, 28102, 30870, 44479, 44748, 50453, 59182, 60426, 63687, 68221, 69601, 69612, 70874, 73336, 75221, 79453, 91221, 98975, 99077, 102124, 104548, 114134, 114852, 120241, 125774, 127510, 139021, 169855, 170837, 176186, 176434, 177141, 178047, 178511, 182363, 183198, 184250, 189043, 194301, 198281, 204587, 206860, 214620, 219217, 219427, 221891, 221983, 222585, 226079, 235104, 240792, 245078, 246042, 248252, 261605, 262675, 266908, 268532, 270882, 284817, 288086, 288453, 293858, 294903, 298210, 304636, 308172, 308805, 312159, 313760, 313931, 317052, 317742, 318004, 328754, 328846, 356518, 367453, 371453, 375908, 378131, 391316, 397795, 406666, 415867, 420892, 427415, 427659, 430038, 431287, 437559, 450809, 460784, 469912, 476854, 484316, 487275
}
local GemsTable = {
}
-- Code
repeat wait() until plr:FindFirstChild("ValueFolder")
script.Parent.Clicks.confirmBtn.MouseButton1Click:Connect(function()
if PlrStats.MultiLevel.Value < Settings.MultiplierCap then
game:GetService("ReplicatedStorage"):WaitForChild("Communication"):WaitForChild("Events"):WaitForChild("Upgrade"):FireServer("ClickMulti")
else
local template = plr.PlayerGui.RewardInterface.List.UIListLayout.Template:Clone()
template.Parent = plr.PlayerGui.RewardInterface.List
template.Text = "you cant upgrade to more than x".. Settings.MultiplierCap .."!"
template.TextColor3 = Color3.fromRGB(255, 43, 46)
game:GetService("TweenService"):Create(script.Parent.Multi.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(255, 43, 46)}):Play()
wait(.6)
game:GetService("TweenService"):Create(script.Parent.Multi.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(85, 170, 255)}):Play()
end
end)
script.Parent.Gems.confirmBtn.MouseButton1Click:Connect(function()
if PlrStats.GemsLevel.Value < Settings.GemMultiplierCap then
game:GetService("ReplicatedStorage"):WaitForChild("Communication"):WaitForChild("Events"):WaitForChild("Upgrade"):FireServer("GemsMulti")
else
local template = plr.PlayerGui.RewardInterface.List.UIListLayout.Template:Clone()
template.Parent = plr.PlayerGui.RewardInterface.List
template.Text = "you cant upgrade to more than x".. Settings.GemMultiplierCap .."!"
template.TextColor3 = Color3.fromRGB(255, 43, 46)
game:GetService("TweenService"):Create(script.Parent.Gems.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(255, 43, 46)}):Play()
wait(.6)
game:GetService("TweenService"):Create(script.Parent.Gems.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(61, 236, 134)}):Play()
end
end)
local function Update()
script.Parent:WaitForChild("Clicks").Frame.Level.Text = "Lvl.".. PlrStats.MultiLevel.Value
script.Parent:WaitForChild("Gems").Frame.Level.Text = "Lvl.".. PlrStats.GemsLevel.Value
script.Parent:WaitForChild("Clicks").Frame.Count.Text = abbreviate(PriceTable[PlrStats.MultiLevel.Value])
script.Parent:WaitForChild("Gems").Frame.Count.Text = abbreviate(PriceTable[PlrStats.GemsLevel.Value])
script.Parent:WaitForChild("Gems").Frame.BarBG.BarLine.Size = UDim2.new(PlrStats.GemsLevel.Value/Settings.GemMultiplierCap, 0,1, 0)
script.Parent:WaitForChild("Clicks").Frame.BarBG.BarLine.Size = UDim2.new(PlrStats.MultiLevel.Value/Settings.MultiplierCap, 0,1, 0)
end
spawn(Update)
plr.ValueFolder.GemsLevel:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Gems.Frame.BarBG.BarLine.Size = UDim2.new(PlrStats.GemsLevel.Value/Settings.GemMultiplierCap, 0,1, 0)
local template = plr.PlayerGui.RewardInterface.List.UIListLayout.Template:Clone()
template.Parent = plr.PlayerGui.RewardInterface.List
template.Text = "successfully upgraded Clicks to x".. PlrStats.MultiLevel.Value .."!"
template.TextColor3 = Color3.fromRGB(0, 255, 127)
script.Parent.Gems.Frame.Level.Text = "Lvl.".. PlrStats.GemsLevel.Value
script.Parent:WaitForChild("Gems").Frame.Count.Text = abbreviate(PriceTable[PlrStats.GemsLevel.Value])
game:GetService("TweenService"):Create(script.Parent.Gems.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(0, 255, 127)}):Play()
wait(.6)
game:GetService("TweenService"):Create(script.Parent.Gems.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(85, 170, 255)}):Play()
end)
PlrStats.MultiLevel:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Clicks.Frame.BarBG.BarLine.Size = UDim2.new(PlrStats.MultiLevel.Value/Settings.MultiplierCap, 0,1, 0)
local template = plr.PlayerGui.RewardInterface.List.UIListLayout.Template:Clone()
template.Parent = plr.PlayerGui.RewardInterface.List
template.Text = "successfully upgraded Clicks to x".. PlrStats.MultiLevel.Value .."!"
template.TextColor3 = Color3.fromRGB(0, 255, 127)
script.Parent.Clicks.Frame.Level.Text = "Lvl.".. PlrStats.MultiLevel.Value
script.Parent:WaitForChild("Clicks").Frame.Count.Text = abbreviate(PriceTable[PlrStats.MultiLevel.Value])
game:GetService("TweenService"):Create(script.Parent.Clicks.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(0, 255, 127)}):Play()
wait(.6)
game:GetService("TweenService"):Create(script.Parent.Clicks.confirmBtn, TweenInfo.new(0.5), {BackgroundColor3 = Color3.fromRGB(85, 170, 255)}):Play()
end)
Server:
local MaxClick = 100
local MaxGem = 6
local PriceTable = {
12256, 14946, 25765, 28102, 30870, 44479, 44748, 50453, 59182, 60426, 63687, 68221, 69601, 69612, 70874, 73336, 75221, 79453, 91221, 98975, 99077, 102124, 104548, 114134, 114852, 120241, 125774, 127510, 139021, 169855, 170837, 176186, 176434, 177141, 178047, 178511, 182363, 183198, 184250, 189043, 194301, 198281, 204587, 206860, 214620, 219217, 219427, 221891, 221983, 222585, 226079, 235104, 240792, 245078, 246042, 248252, 261605, 262675, 266908, 268532, 270882, 284817, 288086, 288453, 293858, 294903, 298210, 304636, 308172, 308805, 312159, 313760, 313931, 317052, 317742, 318004, 328754, 328846, 356518, 367453, 371453, 375908, 378131, 391316, 397795, 406666, 415867, 420892, 427415, 427659, 430038, 431287, 437559, 450809, 460784, 469912, 476854, 484316, 487275
}
local GemsTable = {
}
game:GetService("ReplicatedStorage"):WaitForChild("Communication"):WaitForChild("Events"):WaitForChild("Upgrade").OnServerEvent:Connect(function(plr, typ)
if typ == "ClickMulti" then
if plr.ValueFolder.Gemstones.Value >= tonumber(PriceTable[plr.ValueFolder.MultiLevel.Value]) then
if plr.ValueFolder.Multiplier.Value <= MaxClick then
plr.ValueFolder.Gemstones.Value -= PriceTable[plr.ValueFolder.MultiLevel.Value]
if plr.ValueFolder.MultiLevel.Value ~= MaxClick then
plr.ValueFolder.MultiLevel.Value += 1
end
if plr.ValueFolder.Multiplier.Value ~= MaxClick then
plr.ValueFolder.Multiplier.Value += 1
end
return
end
end
elseif typ == "GemsMulti" then
if plr.ValueFolder.GemsLevel.Value == 0 then
if plr.ValueFolder.Gemstones.Value >= 500 then
plr.ValueFolder.Gemstones.Value -= 500
plr.ValueFolder.GemsLevel.Value += 1
end
return
end
if plr.ValueFolder.Gemstones.Value >= tonumber(PriceTable[plr.ValueFolder.GemsLevel.Value]) then
if plr.ValueFolder.GemsMulti.Value <= MaxGem then
plr.ValueFolder.Gemstones.Value -= PriceTable[plr.ValueFolder.GemsLevel.Value]
plr.ValueFolder.GemsLevel.Value += 1
if plr.ValueFolder.GemsMulti.Value ~= MaxGem then
plr.ValueFolder.GemsMulti.Value += 1
end
end
end
end
end)
I have tried to find many solutions but couldn’t figure any out which could fix this issue.
Thanks for taking your time to help me!