Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ServerScriptService.Tool:19: attempt to compare string with number?

So I am creating a tool giver system, and there are a remote function and a local script. Whenever you click a button it should invoke the remote function but while doing this the script errors: 19:40:29.649 - ServerScriptService.Tool:19: attempt to compare string with a number.

Please Help -- Yours truly, suspectshot108

Local Script: Broken -- Line.. uhh well whenever u invoke the server.

local EventFolder = game:GetService("ReplicatedStorage").Functions
local RequestTool = EventFolder:WaitForChild("RequestTool")

for _,btn in pairs(script.Parent:GetChildren()) do
	if btn:IsA("TextButton") and btn.Name == "Item" then
		btn.MouseButton1Click:Connect(function()
			local Cost = btn:WaitForChild("Cost").Value
			local Name = btn:WaitForChild("Name").Value
			
			RequestTool:InvokeServer(Name,Cost)
		end)
	end
end

Script: Works Fine -- I think...

--[[
	File Name: Tool Request Accepted;
	Writen by suspectshot108;
	Version: 1.0
--]]

local EventFolder = game:GetService("ReplicatedStorage").Functions
local RequestTool = EventFolder:WaitForChild("RequestTool")

RequestTool.OnServerInvoke = function(Player,Name,Cost)
	if Player ~= nil then
		if Player.leaderstats and Player.Security then
			if Player.leaderstats.Bits and Player.Security.Bits then
				if string.match(Player.leaderstats.Bits.Value,Player.Security.Bits.Value) then
					local Ls = Player.leaderstats
					local Sy = Player.Security
					local Tl
					local Ne = "Bits"
					if Ls[Ne].Value and Sy[Ne].Value >= Cost then
						Tl = game:GetService("ReplicatedStorage").Tools[Name]:Clone()
						Tl.Parent = Player.Backpack
						wait()
						Ls[Ne].Value = Ls[Ne].Value - Cost
						Sy[Ne].Value = Sy[Ne].Value - Cost
					end
				else
					Player:Kick("Something is wrong with your leaderstats.")
				end
			end
		end
	end
end

4 comments

0

According to the error, the problem is in the server script on line 19. If you look at it closely, it says what script and what line every time it shows an error.

0

I don't get it...

0

19:40:29.649 - ServerScriptService.Tool:19: attempt to compare string with a number. "ServerScriptService.Tool" shows what script the problem is in. The number after it is the line number.

0

Try use IntValue instead of String Value.

2 answers

✓ Accepted answer

From what I understand, you are using StringValue instead of IntValue, it is recommended that you change its value to IntValue.

Errors: You should use IntValue instead of StringValue to use Values with numbers. but there are ways to do it with StringValue. If you want to use StringValue you need to use tostring() and tonumber()

however if you want to continue with StringValue you can try this:

You can see tostring() and tonumber() here: tonumber() - tostring()

For this you need to detect with number, and change with string.

Fixed script:

--[[
    File Name: Tool Request Accepted;
    Writen by suspectshot108;
    Version: 1.0
--]]

local EventFolder = game:GetService("ReplicatedStorage").Functions
local RequestTool = EventFolder:WaitForChild("RequestTool")

RequestTool.OnServerInvoke = function(Player,Name,Cost)
    if Player ~= nil then
        if Player.leaderstats and Player.Security then
            if Player.leaderstats.Bits and Player.Security.Bits then
                if string.match(Player.leaderstats.Bits.Value,Player.Security.Bits.Value) then
                    local Ls = Player.leaderstats
                    local Sy = Player.Security
                    local Tl
                    local Ne = "Bits"
					if Ls[Ne].Value ~= nil and Sy[Ne].Value ~= nil then
	                    if tonumber(Ls[Ne].Value) and tonumber(Sy[Ne].Value) >= Cost then
	                        Tl = game:GetService("ReplicatedStorage").Tools[Name]:Clone()
	                        Tl.Parent = Player.Backpack
	                        wait()
							local LSnE = Ls[Ne].Value
							local SYnE = Sy[Ne].Value
	                        Ls[Ne].Value = Ls[Ne].Value - tostring(Cost)
	                        Sy[Ne].Value = Sy[Ne].Value - tostring(Cost)
	                    end
					end
                else
                    Player:Kick("Something is wrong with your leaderstats.")
                end
            end
        end
    end
end

Hope it helped! :)

4 comments

0

Any errors? tell-me!

0

Ooh, nice. Didn't know you could do that.

0

I thought about it at the time, I would only need to detect if the Value in number is greater than cost and remove the value with string, because it is a string value. i tryed to make to remove with number, but dont work. and i put with string and works. it was just a simple script.

0

oof sorry for my noob scripting and the 1 year wait!

So since the problem is in the server script on line 19, that means there's a flaw in . . .

if Ls[Ne].Value and Sy[Ne].Value >= Cost then

I think the problem is that you set Ne, to a string, aka a text, and Ls to leaderstats. I'm not sure what kind of object leaderstats is, but it's probably not a number. I'm also assuming that "Cost" is a number. So the error is saying you're trying to ask if a string is greater than or equal to a number. I don't really understand what exactly you're trying to do with the script, but just pay attention to that, and try to figure it out from there.

2 comments

0

Ls[Ne] aka Ls.Bits

0

What I was saying is I doubt leaderstats and Security are IntValues, but if they are, then the problem is Ne because it's a string, and cost probably isn't.

This discussion is preserved as it was. New answers, comments, and votes are closed.