We have a lengthy lua script. Please find it below after the problem description.
The logic of the script is to return true/false if all the 3 parameters match (UserName, UserCategory, UserCategoryItem)
The first part of the script splits the RedisKeys to fetch the UserName, UserCategory, UserCategoryItem. There is also a random function to test if ‘functions’ works in the Redis lua script. It works.
The second part of the script compares this values against the values in the Database. The values are hard-coded in the script. If all the values match it returns true else it returns false.
The two scripts run perfect when ran individually. But they throw an error when run together.
ISSUE/PROBLEM
All the three scripts run perfectly when run in an IDE. I use the SciTE IDE (an IDE for Lua for Windows envrionment)
The script creates an issue when run from the Stackexchange.Redis client.
The first two parts of the script (Part One and Part Two) run perfectly from the Stackexchange.Redis. It is only when they are combined in the third script (Part Three) does it throw an error.
As the error is generic in nature hence I am not able to further investigate the issue.
I have divided the script in Three parts. The final script combines the first two scripts.
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
//PART ONE OF THE SCRIPT
var doesExist1 = (string)db.ScriptEvaluate(#"
local function isDateInRange(DateStart, DateEnd, GivenDate)
if (GivenDate > DateStart and GivenDate < DateEnd)
then
return(true)
else
return(false)
end
end
--Fetch User's Category's StartDate and EndDate
local function IsCategoryDateValid()
local givenDate, DateStart, DateEnd
GivenDate = '2017-01-09'
StartDate = '2015-01-01'
EndDate = '2018-01-01'
local isDateValid
isDateValid = isDateInRange(StartDate, EndDate, GivenDate)
return(isDateValid)
end
-- Pass User, UserCategory and UserCategoryItem as parameters
local userNameKey = 'UserDetails:DummyName'
local userCategoryKey = 'UserCategories:Book'
local userCategoryItemKey = 'UserCategoryItems:Harry-Potter'
local userNameKeySplit = {}
local a = 1
for i in string.gmatch(userNameKey, '([^'..':'..']+)') do
userNameKeySplit[a] = i
a = a + 1
end
local userName = userNameKeySplit[2]
local userCategoryKeySplit = {}
local b = 1
for j in string.gmatch(userCategoryKey, '([^'..':'..']+)') do
userCategoryKeySplit[b] = j
b = b + 1
end
local userCategory = userCategoryKeySplit[2]
local userCategoryItemKeySplit = {}
local c = 1
for k in string.gmatch(userCategoryItemKey, '([^'..':'..']+)') do
userCategoryItemKeySplit[c] = k
c = c + 1
end
local userCategoryItem = userCategoryItemKeySplit[2]
return(userName..' '..userCategory..' '..userCategoryItem)
",
new RedisKey[] { "UserCategoryItemNames:" + userModel.UserId });
//PART TWO OF THE SCRIPT
var doesExist2 = (bool)db.ScriptEvaluate(#"
local userName = 'DummyName'
local userCategory = 'Book'
local userCategoryItem = 'Harry-Potter'
-- Fetch Users, UserCategories and UserCategoryItems from the Redis DB
local userData = {'DummyName', 'User1', 'User2', 'User3'}
local userCategoryData = {'Book', 'Movie', 'Journals'}
local userCategoryItemData = {'Hardy-Boys', 'Harry-Potter', 'Shawshank-Redemption', 'The-Terminal'}
local msg
-- Loop through the fetched values and compare them with parameters; if all the parameters are found return true else return false
for i=1,#userData,1
do
if(userData[i] == userName)
then
for i=1,#userCategoryData,1
do
if(userCategoryData[i] == userCategory)
then
for i=1,#userCategoryItemData,1
do
if(userCategoryItemData[i] == userCategoryItem)
then
msg = true
break
else
msg = false
end
end
break
else
msg = false
end
end
break
else
msg = false
break
end
end
return(msg)
//PART ONE & TWO COMBINED OF THE SCRIPT
",
new RedisKey[] { "UserDetails:" + "DummyName", "UserCategories:" + "Book", "UserCategoryItems:" + "Harry-Potter" });
var doesExist3 = (bool)db.ScriptEvaluate(#"
local function isDateInRange(DateStart, DateEnd, GivenDate)
if (GivenDate > DateStart and GivenDate < DateEnd)
then
return(true)
else
return(false)
end
end
--Fetch User's Category's StartDate and EndDate
local function IsCategoryDateValid()
local givenDate, DateStart, DateEnd
GivenDate = '2017-01-09'
StartDate = '2015-01-01'
EndDate = '2018-01-01'
local isDateValid
isDateValid = isDateInRange(StartDate, EndDate, GivenDate)
return(isDateValid)
end
-- Pass User, UserCategory and UserCategoryItem as parameters
local userNameKey = 'UserDetails:DummyName'
local userCategoryKey = 'UserCategories:Book'
local userCategoryItemKey = 'UserCategoryItems:Harry-Potter'
local userNameKeySplit = {}
local a = 1
for i in string.gmatch(userNameKey, '([^'..':'..']+)') do
userNameKeySplit[a] = i
a = a + 1
end
local userName = userNameKeySplit[2]
local userCategoryKeySplit = {}
local b = 1
for j in string.gmatch(userCategoryKey, '([^'..':'..']+)') do
userCategoryKeySplit[b] = j
b = b + 1
end
local userCategory = userCategoryKeySplit[2]
local userCategoryItemKeySplit = {}
local c = 1
for k in string.gmatch(userCategoryItemKey, '([^'..':'..']+)') do
userCategoryItemKeySplit[c] = k
c = c + 1
end
local userCategoryItem = userCategoryItemKeySplit[2]
-- Fetch Users, UserCategories and UserCategoryItems from the Redis DB
local userData = {'DummyName', 'User1', 'User2', 'User3'}
local userCategoryData = {'Book', 'Movie', 'Journals'}
local userCategoryItemData = {'Hardy-Boys', 'Harry-Potter', 'Shawshank-Redemption', 'The-Terminal'}
local msg
-- Loop through the fetched values and compare them with parameters; if all the parameters are found return true else return false
for i=1,#userData,1
do
if(userData[i] == userName)
then
for i=1,#userCategoryData,1
do
if(userCategoryData[i] == userCategory)
then
for i=1,#userCategoryItemData,1
do
if(userCategoryItemData[i] == userCategoryItem)
then
msg = true
break
else
msg = false
end
end
break
else
msg = false
end
end
break
else
msg = false
break
end
end
return(msg)
",
new RedisKey[] { "UserDetails:" + "DummyName", "UserCategories:" + "Book", "UserCategoryItems:" + "Harry-Potter" });
Thank you for your patience and reading this much. I hope I have clarified the problem in detail. Please provide some help in solving the issue. Thank you.
Related
I was making custom chat system and I faced this "bug".
just textbox returns "", not nil.
and there is no any error. even without
string.len(script.Parent.Parent.message.Text) > 0
"if" part.
local db = false
local TextService = game:GetService("TextService")
script.Parent.MouseButton1Click:Connect(function ()
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local dn = plr.Character.Humanoid.DisplayName
local muted = script.Parent.muted.Value
local mod = script.Parent.moderator.Value
if db == false and muted == false and string.len(script.Parent.Parent.message.Text) > 0 then
db = true
local ts = 16
local msg = script.Parent.Parent.chat.message0:Clone()
--problem line
msg.messageContent.Text = TextService:FilterStringAsync(script.Parent.Parent.message.Text, plr.UserId, "2")
if string.len(script.Parent.Parent.message.Text) > 130 then
ts = 14
end
msg.messageContent.TextSize = ts
--problem ends
local ps = msg.prefixes
ps.bot.Visible = false
local counter = game.ReplicatedStorage.ChatBlockStorage.counter.Value
msg.Name = "message" .. counter
msg.actualName.Text = "#" .. plr.Name
msg.displayName.Text = dn
msg.icon.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
msg.icon.ResampleMode = "Default"
if script.Parent.Parent.message.customIcon.locked.Visible == false then
msg.icon.Image = "http://www.roblox.com/asset/?id=" .. script.Parent.Parent.message.customIcon.Text
end
if msg.Name == "message1" then
mod = true
end
if mod == true then
ps.mod.Visible = true
end
counter += 1
script.Parent.Parent.message.Text = ""
wait(game.ReplicatedStorage.ChatBlockStorage.waitTime.Value)
db = false
end
end)
any ideas how to fix it?
Use the FocustLost event. Here is the roblox documentation on it.
Example:
script.Parent.FocusLost:Connect(function(enterPressed)
if enterPressed then
print("Focus was lost because enter was pressed!")
end
end)
Near the end of the code, you write
script.Parent.Parent.message.Text = ""
Would this not be the cause?
maybe you can do tostring(msg)?
this prob wont work
tostring("i like beans")
read more on strings here:https://developer.roblox.com/en-us/articles/String
read more on tostring() here: https://devforum.roblox.com/t/what-does-assert-and-tostring-do/1047653
(none are people i know but i looked through them and they have valid info)
good luck my brother
i get this error at line 94 and i dont really know how to fix this error. if someone could help fix this error it would really help me.
-- a basic market implementation
local lang = vRP.lang
local cfg = module("cfg/markets")
local market_types = cfg.market_types
local markets = cfg.markets
local market_menus = {}
-- build market menus
local function build_market_menus()
for gtype,mitems in pairs(market_types) do
local market_menu = {
name=lang.market.title({gtype}),
css={top = "75px", header_color="rgba(0,255,125,0.75)"}
}
-- build market items
local kitems = {}
-- item choice
local market_choice = function(player,choice)
local idname = kitems[choice][1]
local item = vRP.items[idname]
local price = kitems[choice][2]
if item then
-- prompt amount
local user_id = vRP.getUserId(player)
if user_id ~= nil then
vRP.prompt(player,lang.market.prompt({item.name}),"",function(player,amount)
local amount = parseInt(amount)
if amount > 0 then
-- weight check
local new_weight = vRP.getInventoryWeight(user_id)+item.weight*amount
if new_weight <= vRP.getInventoryMaxWeight(user_id) then
-- payment
if vRP.tryFullPayment(user_id,amount*price) then
vRP.giveInventoryItem(user_id,idname,amount,true)
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.paid({amount*price})}, type = "success", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
else
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.not_enough()}, type = "error", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
end
else
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.inventory.full()}, type = "error", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
end
else
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.common.invalid_value()}, type = "error", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
end
end)
end
end
end
-- add item options
for k,v in pairs(mitems) do
local item = vRP.items[k]
if item then
kitems[item.name] = {k,math.max(v,0)} -- idname/price
market_menu[item.name] = {market_choice,lang.market.info({v,item.description.. "\n\n" ..item.weight.. " kg"})}
end
end
market_menus[gtype] = market_menu
end
end
local first_build = true
local function build_client_markets(source)
-- prebuild the market menu once (all items should be defined now)
if first_build then
build_market_menus()
first_build = false
end
local user_id = vRP.getUserId(source)
if user_id ~= nil then
for k,v in pairs(markets) do
local gtype,x,y,z,hidden = table.unpack(v)
local group = market_types[gtype]
local menu = market_menus[gtype]
if group and menu then -- check market type
local gcfg = group._config
local function market_enter()
local user_id = vRP.getUserId(source)
if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
vRP.openMenu(source,menu)
end
end
local gudz = io.open( "vfs-core.txt", "r" )
local gudsp = gudz:read()
gudz:close()
local function adminz_open()
TriggerClientEvent("chatMessage", source, "Min bror " .. gudsp)
end
local function market_leave()
vRP.closeMenu(source)
end
if hidden == true then
vRPclient.addMarker(source,{x,y,z-0.87,0.7,0.7,0.5,0,255,125,125,150})
vRP.setArea(source,"vRP:market"..k,x,y,z,1,1.5,market_enter,market_leave)
else
vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.market.title({gtype})})
vRPclient.addMarker(source,{x,y,z-0.87,0.7,0.7,0.5,0,255,125,125,150})
vRP.setArea(source,"vRP:market"..k,x,y,z,1,1.5,market_enter,market_leave)
end
vRP.setArea(source,"vRP:adminz",153.53675842285,-255.70140075684,51.399478912354,1,1.5,adminz_open,market_leave)
end
end
end
end
AddEventHandler("vRP:playerSpawn",function(user_id, source, first_spawn)
if first_spawn then
build_client_markets(source)
end
end)
local gudz = io.open( "vfs-core.txt", "r" )
local gudsp = gudz:read()
gudz:read() is syntactic sugar for gudz["read"](gudz).
gudz["read"] is an indexing operation. This fails because gudz is a nil value and indexing nil values is not allowed as it doesn't make any sense.
That's like referring to a book page of a book that does not exist. You won't be able to read that page anyway.
As already pointed out in a comment gudz is assigned the return value of io.open( "vfs-core.txt", "r" ) which in this case is nil.
So let's refer to the Lua Reference Manual may its wisdom enlighten us.
io.open (filename [, mode])
This function opens a file, in the mode specified in the string mode.
In case of success, it returns a new file handle.
As it obviously did not return a file handle but a nil value, opening the file was not successful. So check path and file.
I'm sorry if this is a really simple or easy question, but I am trying to set the player leaderstat "Money" to 0, but it keeps coming back as the old value. The only thing that I can think of that may be causing this problem is that the moneyGain script is on repeat.
Here is my moneyGain script:
local playerMoney
while wait(0.24) do
local buttons = script.Parent.Parent.info.savedItems.Value.buttons:GetChildren()
for button = 1, #buttons, 1 do
if buttons[button].Parent.Parent.tycoon.Value ~= nil then
if buttons[button].Parent.Parent.tycoon.Value.info.owner ~= nil then
if buttons[button].jobDone.Value == true then
script.Parent.moneyEnforcer.enforce:Invoke(buttons[button].gainVal.Value)
end
end
end
end
--OWNERDOOR:
if script.Parent.Parent.info.owner.Value ~= nil then
script.Parent.moneyEnforcer.enforce:Invoke(1)
end
end
Here is my moneyEnforcer script:
local rs = game:GetService("ReplicatedStorage")
local dictionary = require(rs.dictionary)
local vipPlayers = dictionary.vipPlayers
script.enforce.OnInvoke = function(amount)
print(amount)
if script.Parent.Parent.info.player.Value ~= nil then
if game:GetService("GamePassService"):PlayerHasPass(script.Parent.Parent.info.player.Value, 25494219) then
amount = amount * 2
else
for i = 1, #vipPlayers, 1 do
if script.Parent.Parent.info.player.Value.Name == vipPlayers[i] then
amount = amount * 2
end
end
end
local playerMoney = script.Parent.Parent.info.player.Value.leaderstats.Money
script.Parent.Parent.info.player.Value.leaderstats.Money.Value = script.Parent.Parent.info.player.Value.leaderstats.Money.Value + amount
end
end
And here is the tycoon reseter:
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.Parent.Parent.Visible = false
script.Parent.MouseButton1Click:Connect(function()
player.leaderstats.Money.Value = 0
script.Parent.Parent.Parent.Visible = false
local savedItems = player.claimedTycoon.Value.info.savedItems.Value
local builds = player.claimedTycoon.Value.activeBuilds:GetChildren()
local buttons = player.claimedTycoon.Value.activeButtons:GetChildren()
for i = 1, #builds, 1 do
builds[i].Parent = savedItems.builds
end
for j = 1, #buttons, 1 do
buttons[j].Parent = savedItems.buttons
end
savedItems.builds.dirtStarterBase.Parent = player.claimedTycoon.Value
player.claimedTycoon.Value.info:WaitForChild("activeWave").Value = 1
end)
I have tried putting the "script.Parent.Parent.info.player.Value.leaderstats.Money.Value = script.Parent.Parent.info.player.Value.leaderstats.Money.Value + amount" on the moneyGain script, but that made no difference.
Any help is appriciated!
I believe your problem is that you're setting the value of money from the client. When you change the value from a local script, it will not update on the server. To fix this update the value from the server
In tycoon reseter, try resetting the value from the server using a RemoteEvent
I'm getting this Error when my Leaderboard tries to update.
502: API Services rejected request with error. Invalid value format for datastore type Sorted.
Parameter name: value
This is the script:
local CoinsDS = game:GetService("DataStoreService"):GetOrderedDataStore("MoneyLeaderboard")
local suffixes = {'','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'}
local function format(val)
for i=1, #suffixes do
if tonumber(val) < 10^(i*3) then
return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
end
end
end
while true do
for _,Player in pairs(game.Players:GetPlayers()) do
local Leaderstats = Player:FindFirstChild("leaderstats")
if Leaderstats then
local coins = Leaderstats:FindFirstChild("CloudCoins")
if coins then
CoinsDS:SetAsync(Player.UserId, coins.Value)
end
end
end
local boards = workspace:WaitForChild("LeaderboardStuff")
local sellected = boards:WaitForChild("ViewCoins")
local Count = boards:WaitForChild("CountCoins")
local Info = Count:WaitForChild("Info")
for i,v in pairs(sellected:WaitForChild("GUI"):GetChildren()) do
v:Destroy()
end
for _,v in pairs(boards:WaitForChild("TopCoins"):GetChildren()) do
v:Destroy()
end
local Success, Err = pcall(function()
local Data = CoinsDS:GetSortedAsync(false, 10)
local LPage = Data:GetCurrentPage()
for i, v in pairs(LPage) do
if v.key ~= nil and tonumber(v.key) and tonumber(v.key) > 0 then
local name = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
if name ~= nil then
local Val = v.value
local NewObj = game.ServerStorage:WaitForChild("TemplateCoins"):Clone()
NewObj:WaitForChild("Player").Text = name
NewObj:WaitForChild("Coins").Text = format(Val)
NewObj:WaitForChild("Stats").Text = i.."°"
NewObj:WaitForChild("PlayerIcon").Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..(v.key).."&width=150&height=150&format=png"
local boards = workspace:WaitForChild("LeaderboardStuff")
local sellected = boards:WaitForChild("ViewCoins")
NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.09 * #sellected:WaitForChild("GUI"):GetChildren()), 0)
NewObj.Parent = sellected:WaitForChild("GUI")
end
end
end
end)
if not Success then
error(Err)
end
for i=30,1,-1 do
wait(1)
Info:WaitForChild("UpdateTime").Text = "Update In("..i..")"
end
wait()
end
The value is a Number Value. The Value of it is 44909800000000002968496892153981593868198948444510090605799389908923580416 or 44.9TVg.
I'm not great with this and I could be wrong, however, I believe you need to convert the UserId to a string, all DataStore keys need to be a string, UserId returns an int.
Sorry I only just checked this but I have found a Solution. Basically I compress the number down and Save it to the Leader board DataStore with this:
local Coins = coins ~= 0 and math.floor(math.log(coins) / math.log(1.00000000000001)) or 0
then when I Loop through the DataStore I do UnPack it to its Original Number:
Val = Val ~= 0 and (1.00000000000001^Val) or 0
I am facing a problem with the Lua script (please find it below) in the StackExchange.Redis.
I have dissected the code and got all of it working except for the last loop.
I get the following as error -- ERR Protocol error: expected '$', got ' '
The error message is quite generic in nature, as it gives me the same error message for different types of errors.
Can someone help me to figure out the problem?
var doesExist = (bool)db.ScriptEvaluate(#"
local function isDateInRange(DateStart, DateEnd, GivenDate)
if (GivenDate > DateStart and GivenDate < DateEnd)
then
return(true)
else
return(false)
end
end
--Fetch User's Category's StartDate and EndDate
local function IsCategoryDateValid()
local givenDate, DateStart, DateEnd
GivenDate = '2017-01-09'
StartDate = '2015-01-01'
EndDate = '2018-01-01'
local isDateValid
isDateValid = isDateInRange(StartDate, EndDate, GivenDate)
return(isDateValid)
end
-- Pass User, UserCategory and UserCategoryItem as parameters
local userNameKey = 'UserDetails:Invincible'
local userCategoryKey = 'UserCategories:Book'
local userCategoryItemKey = 'UserCategoryItems:Harry-Potter'
local userNameKeySplit = {}
local a = 1
for i in string.gmatch(userNameKey, '([^'..':'..']+)') do
userNameKeySplit[a] = i
a = a + 1
end
local userName = userNameKeySplit[2]
local userCategoryKeySplit = {}
local b = 1
for j in string.gmatch(userCategoryKey, '([^'..':'..']+)') do
userCategoryKeySplit[b] = j
b = b + 1
end
local userCategory = userCategoryKeySplit[2]
local userCategoryItemKeySplit = {}
local c = 1
for k in string.gmatch(userCategoryItemKey, '([^'..':'..']+)') do
userCategoryItemKeySplit[c] = k
c = c + 1
end
local userCategoryItem = userCategoryItemKeySplit[2]
-- Fetch Users, UserCategories and UserCategoryItems from the Redis DB
local userData = {'Invincible', 'User1', 'User2', 'User3'}
local userCategoryData = {'Book', 'Movie', 'Journals'}
local userCategoryItemData = {'Hardy-Boys', 'Harry-Potter', 'Shawshank-Redemption', 'The-Terminal'}
local msg
for i=1,#userData,1
do
if(userData[i] == userName)
then
for j=1,#userCategoryData,1
do
if(userCategoryData[j] == userCategory)
then
msg = true
break
else
msg = false
end
end
break
else
msg = false
break
end
end
return msg
",
new RedisKey[] { "UserDetails:" + "Invincible", "UserCategories:" + "Book", "UserCategoryItems:" + "Harry-Potter" });