I am trying to make a gui that picks a random number, but then I ran into an error saying Attempt to compare number and string.
This is the LocalScript:
local setNumberRangeFunction = game:GetService("ReplicatedStorage"):WaitForChild("SetNumberRangeFunction")
local button = script.Parent
button.MouseButton1Click:Connect(function()
local buttonDefaultText = "Set Number Range"
local function makeErrorMessage(message)
button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
button.Text = message
wait(2)
button.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
button.Text = buttonDefaultText
end
local maxNumText = script.Parent.Parent:WaitForChild("MaxNumber")
local minNumText = script.Parent.Parent:WaitForChild("MinNumber")
if tonumber(maxNumText.Text) or tonumber(minNumText.Text) then
-- Ignore This
else
makeErrorMessage("The number(s) has to be an actual number.")
return
end
local numberRange = setNumberRangeFunction:InvokeServer(maxNumText.Text, minNumText.Text)
if numberRange == "Min > Max" then
makeErrorMessage("The min number is greater than the max number.")
end
if numberRange == "Value = nil" then
makeErrorMessage("One or more numbers are not set.")
end
if numberRange == "Same value" then
makeErrorMessage("The numbers are the same.")
end
if numberRange == "Number too big" then
makeErrorMessage("The max number is too big. The max number allowed is 1000000000.")
end
if numberRange == "Success" then
button.Text = "Success!"
wait(2)
button.Text = buttonDefaultText
end
end)
This is the ServerScript:
local numberRangeFunction = game:GetService("ReplicatedStorage"):WaitForChild("SetNumberRangeFunction")
numberRangeFunction.OnServerInvoke = function(player, maxNum, minNum)
if maxNum == "" or minNum == "" then
return "Value = nil"
end
if minNum > maxNum then
return "Min > Max"
end
if minNum == maxNum then
return "Same value"
end
if maxNum > 1000000000 then
return "Number too big"
end
if maxNum ~= "" and minNum ~= "" then
if minNum < maxNum then
local maxNumValue = script:WaitForChild("MaxNumber")
local minNumValue = script:WaitForChild("MinNumber")
maxNumValue.Value = tonumber(maxNum)
minNumValue.Value = tonumber(minNum)
return "Success"
end
end
end

1 comment
Well tell us where the error is instead of telling us the problem then giving us a book