Getting an error in a currency script in ROBLOX studio - scripting

I am getting an error in my currency script in Roblox studio
local currencyName = "Coins"
local DataStore = game:GetService(("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID =""currencyName.."-"..player.UserId
local savedData = nil
pcall(function())
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
curreny.Value = savedData
print("Data loaded")
else
currency.Value = 10 -- amount to a new player
print("New player to the game")
end
end)
game.Plyers.PlayerRemoving:Connect(function(player)
local ID =""currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
-- when game is ready to shut down
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:KICK("This game is shutting down")
end
end
wait(5)
end)
It is giving me this error at line 3:
10:30:47.749 - CurrencyScript.Script:3: Expected ')' (to close '(' at line 2), got 'game'
10:30:49.909 - InsertService cannot be used to load assets from the client

Expected ')' (to close '(' at line 2),
You have too many parentheses in line 2.
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

Related

Reading Redis stream in Lua script

I am trying to read the following stream:
127.0.0.1:6379> xrevrange driver:70 + - count 1
1) 1) "1656531417451-0"
2) 1) "field1"
2) "value1"
3) "isbusy"
4) "true"
How can I read this stream in Lua script and reflect the field isbusy from the stream into the the local Lua variable is_busy?
I could not get my head around Lua collections.
local stream = KEYS[1]
local is_busy = false
local messages = redis.call("XREVRANGE", stream, "+", "-", "COUNT", "1")
for _, message in ipairs(messages) do
end
You need to parse the nested structure:
local id
for _, message in ipairs(messages) do
for i, sub_msg in ipairs(message) do
if i == 1 then
id = sub_msg
else
-- parse attributes
local i = 1
while i < #sub_msg do
local k = sub_msg[i]
local v = sub_msg[i + 1]
if k == "isbusy" then
is_busy = v
end
i = i + 2
end
end
end
end

When returning a table get {}

I am trying to create a maze generation script using the module listed below. I'm having this strange problem were the grid variable has a value, but when return grid is called, it returns and empty table? Here is the code to the module script.
local ServerStorage = game:GetService("ServerStorage")
local cellTemplate = ServerStorage:WaitForChild("Cell")
local Maze = {}
local cellObject = {}
local grid = {}
Maze.Size = 25
Maze.CellWidth = 9
Maze.CellLength = 9
Maze.Offset = Vector3.new(0,0,0)
function Maze.new(x,z) -- Create a new cell
local newCell = {}
setmetatable(newCell,{ -- Allows us to create functions for a cell easier
__index = cellObject
})
newCell.X = math.clamp(x,1,Maze.Size)
newCell.Z = math.clamp(z,1,Maze.Size)
newCell.Visited = false
newCell.Model = cellTemplate:Clone()
newCell.Base = newCell.Model:WaitForChild("Base")
newCell.Model.Name = newCell.Model.Name.. "_".. newCell.X.. "-".. newCell.Z
newCell.Walls = {
["Forward"] = newCell.Model:WaitForChild("Forward");
["Backward"] = newCell.Model:WaitForChild("Backward");
["Left"] = newCell.Model:WaitForChild("Left");
["Right"] = newCell.Model:WaitForChild("Right");
}
if not grid[x] then grid[x] = {} end -- We might not have anything on that x axis yet; inserts it into the table
grid[x][z] = newCell
print(grid)
return newCell
end
function Maze.RenderAll() -- Render every cell; exists for more readibility
for _,cellRow in pairs(grid) do -- Loop through every cell row
for _,cell in pairs(cellRow) do -- Loop through every cell in the row
cell:Render() -- Render the cell
end
end
end
function Maze.Grid() -- Allows other scripts to get the grid but not modify it
return grid
end
function Maze.FilterUnvisited(cells) -- Takes in a table and returns one with only the cells in the table that are unvisited
local unvisited = {}
for _,cell in pairs(cells) do -- Loop through every cell in the table passed
if not cell.Visitied then -- The cell hasn't been visited
table.insert(unvisited,cell)
end
end
return unvisited
end
function Maze.GetCell(x,z)
local cell
if grid[x] and grid[x][z] then
cell = grid[x][z]
else
cell = nil
end
return cell
end
function cellObject:Render() -- Render the cell
self.Model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(self.X * Maze.CellLength,0,self.Z * Maze.CellWidth) + Maze.Offset)) -- Move the cell to the correct position
if self.Visited then -- We have gone through the cell
self.Model.PrimaryPart.Color3 = Color3.new(0,1,0) -- Show that the cell has been visited; used for debugging
end
self.Model.Parent = workspace
end
function cellObject:Neighbours() -- Returns the cell's neigbours
local neighbours = {}
-- Order: Right Left Up Down
if grid[self.X + 1] and grid[self.X + 1][self.Z] then -- A cell with +1 X exists
table.insert(neighbours,grid[self.X + 1][self.Z])
end
if grid[self.X - 1] and grid[self.X - 1][self.Z] then -- A cell with -1 X exists
table.insert(neighbours,grid[self.X - 1][self.Z])
end
if grid[self.X][self.Z + 1] then -- A cell with +1 Z exists
table.insert(neighbours,grid[self.X][self.Z + 1])
end
if grid[self.X][self.Z - 1] then -- A cell with -1 Z exists
table.insert(neighbours,grid[self.X][self.Z - 1])
end
return neighbours
end
function cellObject:RandomNeighbour()
local neighbours = self:Neighbours() -- Gets the neigbours of the current cell
if #neighbours > 0 then
return neighbours[math.random(1,#neighbours)] -- Returns a random neigbour
else
return nil
end
end
function cellObject:WallArray() -- Returns an array of the walls instead of a table
local wallArray = {}
wallArray[1] = self.Walls.Forward
wallArray[2] = self.Walls.Right
wallArray[3] = self.Walls.Left
wallArray[4] = self.Walls.Backward
return wallArray
end
function cellObject:Join(cell) -- Joins 2 cells together
local wallPosition = self.Base.Position:Lerp(cell.Base.Position,.5) -- This will return the position of the wall (excluding the Y)
local cell1Array = self:WallArray()
local cell2Array = cell:WallArray()
for wallIndex,wall in pairs(cell1Array) do
if wall.Position.X == wallPosition.X and wall.Position.Z == wallPosition.Z then -- Its the right wall
wall.Transparency = 1
wall.CanCollide = false
cell2Array[4 - (wallIndex - 1)].Transparency = 1
cell2Array[4 - (wallIndex - 1)].CanCollide = false
break -- We don't need to loop anymore, since we've already removed the walls
end
end
end
function cellObject:Unjoin(cell) -- Unjoins 2 cells
local wallPosition = self.Base.Position:Lerp(cell.Base.Position,.5) -- This will return the position of the wall (excluding the Y)
local cell1Array = self:WallArray()
local cell2Array = cell:WallArray()
for wallIndex,wall in pairs(cell1Array) do
if wall.Position.X == wallPosition.X and wall.Position.Z == wallPosition.Z then -- Its the right wall
wall.Transparency = 0
wall.CanCollide = true
cell2Array[4 - (wallIndex - 1)].Transparency = 0
cell2Array[4 - (wallIndex - 1)].CanCollide = true
break -- We don't need to loop anymore, since we've already added the walls
end
end
end
return Maze
Below is the piece of code I'm having diffuculty with.
function Maze.Grid() -- Allows other scripts to get the grid but not modify it
return grid
end
I have tested printing the grid variable and it's not {} but when I call the function in the script below, I always get {}! I have no idea why this is.
Is this a bug in roblox or am I being stupid?
local ServerScriptService = game:GetService("ServerScriptService")
local Maze = require(ServerScriptService:WaitForChild("Maze"))
local latestX = 0
local latestZ = 0
function CreatePath(cell)
local nextCell = cell:RandomNextCell(false)
if nextCell then -- We have a cell next to the current one
print("Joining cells:",cell,nextCell)
cell:Join(nextCell)
cell.Visited = true
cell:Render()
wait(.01)
CreatePath(nextCell)
else -- It must be the end of the maze
print("Path generated!")
print("Maze end: ".. cell.Model.Name)
cell.Base.Color = Color3.new(1,0,0)
end
end
function GenerateMaze()
local cell = Maze.new(latestX + 1,latestZ + 1) -- Create a new cell
cell:Render() -- Render it
print("Created cell")
latestZ += 1
if latestZ > Maze.Size then -- It has exceeded the max size, move on to a new row
latestX += 1
latestZ = 0
end
if #Maze.Grid() < Maze.Size ^ 2 then
wait(.01)
GenerateMaze()
else
print("Grid completed, generating path...")
CreatePath(Maze.GetCell(1,1))
end
end
GenerateMaze()
You are returning a cached value, or well i don't find out other reason.
You may do (and it's not editable):
function Maze.Grid(i, l)
local passed = 1
local response = {}
for index, v in pairs(grid) do
response[index] = i and passed >= i and l and passed <= l and v or not (i or l) and v
-- basically get more than `i` if it, and minor than `l` if it passed
i = i + 1
end
return response
end
It should work, I don't tested it sorry.

I get an error message in csound and I don't know why

I don't know what is wrong with my code, and I don't know what thie error message I got means. I just started using Csound with Cabbage, and coding in general.
I'm trying to ude 1 slider to set the values of multiple variables. I used the slider to set a value for 1 variable, and used some if-then-else statements to set values for other variables.
if kV0 == 1 then kV = 1, kVA = 0, kVB = 0, kV1 = kV2 = kV3 = kV4 = 0
I expect kV to be set to 1 and all other variables to be set to 0 when kV0 is equal to 1. I keep getting this message:
error: syntax error, unexpected T_IDENT, expecting NEWLINE (token "kV")
line 69:
if kV0 == 1 then kV
Parsing failed due to invalid input!
Code like this isn't valid Csound code and you will need to separate the statements onto separate lines, like so:
if kV0 == 1 then
kV = 1
kVA = 0
kVB = 0
kV1 = 0
kV2 = 0
kV3 = 0
kV4 = 0
endif

Data Type mismatch in criteria expression when Table Adapter Update

I have already been searched solution and can't get the right solution yet.
ObjDRow = DataDataSet.Client.Rows.Find(strClientNo)
With ObjDRow
.ClientName = txtClientName.Text.Trim
.ClientAddr = txtAddr.Text.Trim
If txtRegOffice.Text = "" Then
.ClientRegOfficeAddr = txtAddr.Text.Trim
Else
.ClientRegOfficeAddr = txtRegOffice.Text.Trim
End If
.MailtoCorresAddr = RBtnCorresAddr.Checked
.MailtoRegOffice = RBtnRegOffice.Checked
.ClientHPhone = mskHandPhone.Text.Trim
.ClientPager = mskPagerNo.Text.Trim
.ClientTel = mskTelephone.Text.Trim
.ClientFaxNo = mskFax.Text.Trim
.ClientEmail = txtEmail.Text.Trim
.PrimaryPartner = txtPriPartner.Text.Trim
.SecondPartner = txtSecPartner.Text.Trim
.BroughtInBy = cboPreferredBy.Text.Trim
.PersonIncharge = cboPersonIncharge.Text.Trim
.GLAC = cboGLAcode.Text.Trim
.ContactPerson = txtContactPerson.Text.Trim
.AcraNo = txtAcraNo.Text.Trim
.Active = chkActive.Checked
If dtpfyear.Checked = True Then
.YearEnd = dtpfyear.Text
End If
.DeptNo = cboDeptNo.Text.Trim
.DateJoined = dtDateJoined.Value
If cboClientName.SelectedIndex = -1 Then
.Group = txtClientNo.Text
Else
.Group = cboClientName.SelectedValue
End If
.GroupStatus = RButtonMainYes.Checked
.MainGroup = RButtonSubYes.Checked
If IsDate(dtIncorporationDate.Text) Then
.DateOfIncorporation = dtIncorporationDate.Text
Else
.SetDateOfIncorporationNull()
End If
End With
ObjDRow.EndEdit()
ClientTableAdapter.Update(DataDataSet.Client)
Error is occurs when ClientTableAdapter Update.
This error occurs for some client only.
I already check datatype of database and table adapter's datatype and all datatype are same.
My input value datatype and table adapter's datatype are same.
This error occurs even I command all line of update code (.ClientName to last line) but this error still occurs.WTF
Most answers say this is a single quote problem but In my case, There is no single quote.
All data types are same and input values are the same with datatype.
** Updated**
This error still occurs even I do like=>
ObjDRow = DataDataSet.Client.Rows.Find(strClientNo)
ObjDRow.EndEdit()
ClientTableAdapter.Update(DataDataSet.Client)
There is nothing change just select and update.
But if I remove ObjDRow.EndEdit().All are fine. There is no error.

Assistance in Decrypting Lua script that is obfuscated with Base64 > SSL

Can anyone on here help me on decrypting the SSL encryption that protects this LUA script linked at the end of this topic? Basically they are encoded with Base64 then SSL, but I have no idea how to do the SSL portion. They are used with a program called Bot of Legends, and someone told me that it is possible to break the encryption by dumping the decryption function of said program and using that to get the SSL key, but I have no clue where to even start on that. Basically these scripts work by connecting to an authentication server that is coded into the script, and I have gotten a few on my own by sniffing the traffic to their auth server from network packets to get their server link and essentially created my own auth server with Apache, then redirected the network traffic that goes to their server to my own from the script to get the script validated response. For some scripts that have stronger encryption, its not that easy and I would have to get to the source code to remove the coding that runs the auth server checks. Up until a few days ago I had no knowledge on how lua coding worked and how to even compute how auth server checks could be even possible for coding in a simple text file due to lua obfuscation. So bear with me, I would like if someone can chime in and give me an idea on what I can do.
Regards,
Chris
*** PasteBin link to the script in question in raw format: http://pastebin.com/raw.php?i=bG0VqQGW
The Base64 section is first with the SSL section at the bottom.
print("SSL Decoder version 2.0")
print("Copyright (C) 2015")
print("Decoding Started...")
local infilename = select(1,...)
local outfilename = select(2,...)
local infile = io.open(infilename, "r")
if not infile then
error("Failed to open input file.")
end
local intext = infile:read("*a")
infile:close()
local ssltabletext = intext:match("SSL%s*%(%s*%{([%s,0-9]*)%}%s*%)")
if not ssltabletext then
error("Could not find ssl table in source file.")
end
local ssltable = load("return {"..ssltabletext.."}")()
if #ssltable < 255 then
error("SSL table is too short -- can't find table encryption key.")
end
-- find decryption key for the ssl table
local decrypt = {}
decrypt[0] = 0
for i = 1,255 do
local dec = i
local enc = ssltable[i]
assert(decrypt[enc] == nil)
decrypt[enc] = dec
end
-- decrypt ssl table
for i = 256, #ssltable - 256 do -- not sure what last 256 bytes are
ssltable[i] = decrypt[ssltable[i] ]
end
-- If this does a stack overflow, easy to change to something dumb but more robust
local sslcode = string.char(table.unpack(ssltable, 256, #ssltable - 256))
-- This is interesting --
--print(sslcode)
local keyindex = sslcode:match("local Key%s*=%s*'()")
if not keyindex then
error("Could not find key in decoded ssl table.")
end
local key = sslcode:sub(keyindex)
local length = 0
while true do
local c = key:sub(length+1, length+1)
if c == "" then
error("Key string was not terminated.")
elseif c == "'" then
break
elseif c == "\\" then
local c2 = key:sub(length+2, length+2)
if c2:match("%d") then
local c3 = key:sub(length+3, length+3)
if c3:match("%d") then
local c4 = key:sub(length+4, length+4)
if c4:match("%d") then
length = length + 4
else
length = length + 3
end
else
length = length + 2
end
elseif c2 == "x" then
length = length + 4
else
length = length + 2
end
else
length = length + 1
end
end
key = key:sub(1, length)
if #key == 0 then
error("Key is empty")
end
print("Key Found! > " .. key)
print("Decoding finished, outfile is at > " .. outfilename)
-- find base64
local b64 = intext:match("_G.ScriptCode%s*=%s*Base64Decode%s*%(%s*\"([a-zA-Z0-9/+]*=*)\"%s*%)")
if not b64 then
error("Could not find Base-64 encrypted code in source file.")
end
-- base64 decode
local b64val = {}
for i = 0, 25 do
do
local letter = string.byte("A")
b64val[string.char(letter+i)] = i
end
do
local letter = string.byte("a")
b64val[string.char(letter+i)] = i + 26
end
end
for i = 0, 9 do
local numeral = string.byte("0")
b64val[string.char(numeral+i)] = i + 52
end
b64val["+"] = 62
b64val["/"] = 63
b64val["="] = 0
local encoded = b64:gsub("(.)(.)(.)(.)",function(a,b,c,d)
local n = b64val[a] * (64 * 64 * 64) + b64val[b] * (64 * 64) + b64val[c] * 64 + b64val[d]
local b1 = n % 256; n = (n - b1) / 256
local b2 = n % 256; n = (n - b2) / 256
local b3 = n
if d == "=" then
if c == "=" then
assert(b1 == 0 and b2 == 0)
return string.char(b3)
else
assert(b1 == 0)
return string.char(b3, b2)
end
else
return string.char(b3, b2, b1)
end
end)
-- decode
local decoded = encoded:gsub("()(.)", function(i, c)
local b = c:byte()
local ki = ((i - 1) % #key) + 1
local k = key:byte(ki,ki)
b = b - k
if b < 0 then b = b + 256 end
return string.char(b)
end)
-- verify
local result, err = load(decoded)
if not result then
error("Decoded file could not be loaded -- it may be corrupt... ("..tostring(err)..")")
end
-- output
local outfile = io.open(outfilename, "wb")
if not outfile then
error("Failed to open output file.")
end
outfile:write(decoded)
outfile:close()
This code is by Extreme Coders (https://reverseengineering.stackexchange.com/users/1413/extreme-coders)
how to use it , u need to get lua52.exe
save the code into a text file and name it ssl.lua (for example)
now run cmd and type lua52 ssl yourscript.lua decryptedscript.lua
it will run and decrypt it.