Issues with comparing

I need help, so I’ve been working on an RPG Test, but the main issue is that for my skill upgrades system, it will not work.

What I mean by that is, my comparing script is :

	if tonumber(SetPoints) > 0 then

		if db == false then

			db = true

			--The Scripts

			db = false

		end

	end

Just so you know, the variable, ‘SetPoints’ is a number value from a table. Just think that ‘SetPoints’ is equal to 3.

I’ve been trying to compare it in different ways. Such as, changing the comparing symbol to < or > or =.
ITS NOT WORKING!!!

The table value :

sessionData[player.UserId] = {
	Level = 1,
	Cash = 100,
	Exp = 0,
	Points = 1,
	Strength = 1,
	Defense = 1,
	CritChance = 1,
	Stamina = 1,
}

Any help will be great!

P.S. If you need extra information, I will provide it (maybe)

I need all of your code, I don’t have enough to work with

1 Like

Aight, it’s pretty messy…

local script

local tweenService = game:GetService("TweenService")

local gameSets = require(game.ReplicatedStorage.GameSettings)

local player = game.Players.LocalPlayer

local upgradesFrame = player.PlayerGui:WaitForChild("MainGUI").UpgradesFrame

local rFunc = game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("ChangeData")

local db = false
local menuOpen = false

upgradesFrame.Parent.DataFrame.Background.Holder.SkillUpgrades.MouseButton1Click:Connect(function()
	
	if menuOpen == false then
		
		menuOpen = true
		
		upgradesFrame.Visible = true
		
		local tweenMenu = tweenService:Create(upgradesFrame, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = UDim2.new(0.5, 0, 0.5, 0)})
		tweenMenu:Play()		
		
		local tweenBlur = tweenService:Create(game.Lighting.BackgroundBlur, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Size = 12})
		tweenBlur:Play()
		
	else
		
		menuOpen = false
		
		local tweenMenu = tweenService:Create(upgradesFrame, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = UDim2.new(0.5, 0, 2, 0)})
		tweenMenu:Play()	
		
		local tweenBlur = tweenService:Create(game.Lighting.BackgroundBlur, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Size = 0})
		tweenBlur:Play()
		
		tweenMenu.Completed:Connect(function()
			
			upgradesFrame.Visible = false
			
		end)
		
	end

end)

while wait() do
	
	local data = game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("ReturnData"):InvokeServer(player)

	if data then
		
		local SetPoints = data.Points

		local upgrades = upgradesFrame.Background.Holder
		
		print(data.Points)
		upgrades.Strength.Background.Upgrade.MouseButton1Click:Connect(function()

			if tonumber(SetPoints) ~= 0 then

				if db == false then

					db = true

					rFunc:InvokeServer("Points", 1, "-")	
					rFunc:InvokeServer("Strength", 1, "+")	

					task.wait()

					db = false

				end

			end

		end)
		upgrades.Defense.Background.Upgrade.MouseButton1Click:Connect(function()

			if tonumber(SetPoints) ~= 0 then

				if db == false then

					db = true

					rFunc:InvokeServer("Points", 1, "-")	
					rFunc:InvokeServer("Defense", 1, "+")	

					task.wait()

					db = false

				end

			end

		end)
		upgrades.CritChance.Background.Upgrade.MouseButton1Click:Connect(function()

			if tonumber(SetPoints) ~= 0 then

				if db == false then

					db = true

					rFunc:InvokeServer("Points", 1, "-")
					rFunc:InvokeServer("CritChance", 1, "+")	

					task.wait()

					db = false

				end

			end

		end)
		upgrades.Stamina.Background.Upgrade.MouseButton1Click:Connect(function()

			if tonumber(SetPoints) ~= 0 then

				if db == false then

					db = true

					rFunc:InvokeServer("Points", 1, "-")	
					rFunc:InvokeServer("Stamina", 1, "+")	

					task.wait()

					db = false

				end

			end

		end)
		
		upgrades.Parent.Points.Text = "You have " .. data.Points .. " Point(s)"
		upgrades.Strength.Background.Upgrade.Text = "Upgrade (Lv. " .. data.Strength .. ")"					
		upgrades.Defense.Background.Upgrade.Text = "Upgrade (Lv. " .. data.Defense .. ")"					
		upgrades.CritChance.Background.Upgrade.Text = "Upgrade (Lv. " .. data.CritChance .. ")"					
		upgrades.Stamina.Background.Upgrade.Text = "Upgrade (Lv. " .. data.Stamina .. ")"

		upgradesFrame.Parent.DataFrame.Background.Holder.CashText.Text = "$" .. data.Cash
		
	end
	
end

dataHandler

local Players = game:GetService("Players")
local datastoreService = game:GetService("DataStoreService")

local playerData = datastoreService:GetDataStore("playerData" .. 39)

local notificationsMod = require(game:GetService("ServerStorage"):WaitForChild("NotificationHandler"))

local PlayerHandler = {}

local sessionData = {}

local function setupData(player)
	
	local plrUserId = player.UserId
	
	local data
	local success = pcall(function()
		
		data = playerData:GetAsync(plrUserId)
		
	end)
	
	if success then
		
		if data then
			
			sessionData[plrUserId] = data
			
		else
			
			sessionData[player.UserId] = {
				Level = 1,
				Cash = 100,
				Exp = 0,
				Points = 1,
				Strength = 1,
				Defense = 1,
				CritChance = 1,
				Stamina = 1,
			}
			
		end
		
	end
	
end

local function saveData(player)
	
	local plrUserId = player.UserId
	
	local success = pcall(function()
		
		playerData:SetAsync(plrUserId, sessionData[player.UserId])
		
	end)
	
end

function PlayerHandler.ChangeValue(player, name, value, symbol)
	
	local selectedSymbol
	if symbol then
		
		selectedSymbol = symbol
		
	else
		
		selectedSymbol = "+"
		
	end
	
	local plrUserId = player.UserId
	
	if sessionData[plrUserId] then
		
		if selectedSymbol == "+" then
			
			sessionData[plrUserId][name] = tonumber(sessionData[plrUserId][name]) + value
			notificationsMod.CreateNotification(player, "Increased " .. name .. " by " .. value .. "!")
			
		elseif selectedSymbol == "-" then
			
			sessionData[plrUserId][name] = tonumber(sessionData[plrUserId][name]) - value
			notificationsMod.CreateNotification(player, "Decreased " .. name .. " by " .. value .. "!")
			
		elseif selectedSymbol == "*" then

			sessionData[plrUserId][name] = tonumber(sessionData[plrUserId][name]) * value
			notificationsMod.CreateNotification(player, "Multiplied " .. name .. " by " .. value .. "!")
			
		elseif selectedSymbol == "/" then

			sessionData[plrUserId][name] = tonumber(sessionData[plrUserId][name]) / value
			notificationsMod.CreateNotification(player, "Divided " .. name .. " by " .. value .. "!")
			
		elseif selectedSymbol == "=" then

			sessionData[plrUserId][name] = value

		end
		
	end
	
end

Players.PlayerAdded:Connect(setupData)
Players.PlayerRemoving:Connect(saveData)

function PlayerHandler.ReturnData(player)
	
	return sessionData[player.UserId]
	
end

game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("ReturnData").OnServerInvoke = function(player)
	
	return sessionData[player.UserId]
	
end

game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("ChangeData").OnServerInvoke = function(player, name, value, symbol)
	
	PlayerHandler.ChangeValue(player, name, value, symbol)
	
end

return PlayerHandler

I can’t provide any videos, I can’t figure out how to make a video on this

You could use OBS to record and send a video. I didn’t spot any issues in your code however a video may help me look at it a different way

1 Like

Ok, I can’t download stuff, so I’ll just send u the link to the game. The issue is, my skill upgrades system detects if the points amount is greater than 0, if it is, it will increase the stats. But it doesen’t detect it and i just does it. You can tell that the points go into negatives

Game Link : RPG Test - Roblox

Can’t really see anything wrong, there’s not much code comments telling me what is happening in the scripts.

Anyways, just a heads up, this should all be done on the server if possible. I.e. player clicks → fires PlayerClicked remote event and all the points are handled on the server

1 Like

I guess I’ll try your idea since serverscripts is goofy cool

Edit : Thank you, it worked!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.