LUA unexpected symbol near ')' line local society = - lua

RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local society = 'society_mechanic', function(society)
if amount > 0 and xPlayer.get('money') >= amount then
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
xPlayer.removeMoney(amount)
account.addMoney(amount)
end)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end)
Hello, an error appears in my console when i use script.
Where can the error come from?

You have a syntax error with your function local society = 'society_mechanic', function(society) => end missing.
Correct your code like this :
RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local society = 'society_mechanic', function(society)
if amount > 0 and xPlayer.get('money') >= amount then
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
xPlayer.removeMoney(amount)
account.addMoney(amount)
end)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end
end)

In your code is a end missing. You open a function in local society but doesn't close it.

Related

How can I update the script from limit to weight? Lua

I use this ambulance job that is made in Lua. Unfortunately, being an old script, it's not updated, so it was still set to use "limit" which I changed to "weight" since my gamemode is based on weight as well as the database. But sadly it doesn't work, I get this error.
RegisterServerEvent('esx_ambulancejob:giveItem')
AddEventHandler('esx_ambulancejob:giveItem', function(itemName)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name ~= 'ambulance' then
print(('esx_ambulancejob: %s attempted to spawn in an item!'):format(xPlayer.identifier))
return
elseif (itemName ~= 'medikit' and itemName ~= 'bandage') then
print(('esx_ambulancejob: %s attempted to spawn in an item!'):format(xPlayer.identifier))
return
end
local xItem = xPlayer.getInventoryItem(itemName)
local count = 1
if xItem.weight ~= -1 then (it was xItem.limit before)
count = xItem.weight - xItem.count
end
if xItem.count < xItem.weight then
xPlayer.addInventoryItem(itemName, count)
else
TriggerClientEvent('esx:showNotification', source, _U('max_item'))
end
end)
The error screen when I try to take the item from the pharmacy:
Console Error Image
I don't know which line is 263, but error says object_name.weight is nil.
Watching code, xItem doen't have field weight (xItem.weight = nil).
error is on this line
if xItem.weight ~= -1 then (it was xItem.limit before)
count = xItem.weight - xItem.count
end
for knoing what value is null, you can make, just before a print like this
print("Test: " .. tostring(xItem.weith) .. " - " .. tostring(xItem.count);
But, i think that your operation is false becouse you do
xItem.weight - xItem.count;
maybe you want to make
xItem.weight * xItem.count;

Is there anyway to fix this Error with my Leaderboard?

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

.lua error 'then' expected near 'else'

I am having this error, can't find the error.
local choice_revive = {function(player,choice)
local user_id = vRP.getUserId(player)
if user_id ~= nil then
vRPclient.getNearestPlayer(player,{10},function(nplayer)
local nuser_id = vRP.getUserId(nplayer)
if nuser_id ~= nil then
vRPclient.isInComa(nplayer,{}, function(in_coma)
if in_coma then
if vRP.tryGetInventoryItem(user_id,"medkit",1,true) else
vRP.tryGetInventoryItem(user_id,"smartwatch",1,true)
io.write("Smartwatch: Tilkalder Ambulance")
then
vRPclient.playAnim(player,{false,revive_seq,false}) -- anim
SetTimeout(15000, function()
vRPclient.varyHealth(nplayer,{50}) -- heal 50
end)
end
else
vRPclient.notify(player,{lang.emergency.menu.revive.not_in_coma()})
end
end)
else
vRPclient.notify(player,{lang.common.no_player_near()})
end
end)
end
end,lang.emergency.menu.revive.description()}
I have tried to make, and look for error, but without luck.
- If anyone can fix it, tell me please.
if statement, functions and for statement must be ended with end.
this code must be like that
--Settings--
local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","vRP_smartwatch")
if in_coma then
vRP.tryGetInventoryItem(user_id,"smartwatch",1,true)
io.write("Smartwatch: Tilkalder Ambulance")
end
function vRP.sendServiceAlert(sender, emergency,x,y,z, msg)
local service = services[service_name]
local answered = false
if service then
local players = {}
for k,v in pairs(vRP.rusers) do
local player = vRP.getUserSource(tonumber(k))
-- check user
if vRP.hasPermission(k,service.alert_permission) and player ~= nil then
table.insert(players,player)
end
end
end
end

Roblox OnClick clothers giver script

pnts = script.Pants
shirt = script.Shirt
function onClicked(playerWhoClicked)
end
function GiveClothes(character)
if not character:findFirstChild("Shirt") then
shirt:Clone().Parent = character
else character:findFirstChild("Shirt"):Destroy()
shirt:Clone().Parent = character
end
if not character:findFirstChild("Pants") then
pnts:Clone().Parent = character
else character:findFirstChild("Pants"):Destroy()
pnts:Clone().Parent = character
end
end
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(char)
wait(1.12)
local plr = game.Players:findFirstChild(char.Name)
print(char.Name)
local groupid = 0 -- Id of your group
local plr = game.Players:GetPlayerFromCharacter(part.Parent)
if plr then
if plr:IsInGroup(groupid) then
if plr:GetRoleInGroup(groupId) >= 50
then GiveClothes(char)
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
This script is supposed to give you certain clothes if you click on the button(Script is under the button and yes there is also a ClickDetector),but it only gives you the clothes if you are a certain rank in a Group.
But currently it does not work. How to fix this?
Avoid weird names like pnts, you will probably not die from adding the letter a
The ClickDetector already give you the player
And it is over all messy
Try this:
local Pants = script.Pants
local Shirt = script.Shirt
local GroupID = 42 -- Group id here
script.Parent.ClickDetector.MouseClick:connect(function(Player)
if not Player:IsInGroup(GroupID) then return end
if Player:GetRoleInGroup(GroupID) < 50 then return end
local Character = Player.Character
if Character == nil then return end
-- Get new shirt
local CharacterShirt = Character:findFirstChild("Shirt")
if CharacterShirt then CharacterShirt:Destroy() end
Shirt:Clone().Parent = Character
-- Get new pants
local CharacterPants = Character:findFirstChild("Pants")
if CharacterPants then CharacterPants:Destroy() end
Pants:Clone().Parent = Character
end)
Also make sure to post errors when you ask for help

lua - calling a function from a string

From what I've read on this site the below should work.
Can some kindly soul please point out where I'm going wrong?
I've embedded more description and print returns in the code hopefully to make easier reading
local m = {
{opt = "Solar Panels", cmd = "solarPanel"}
-- There are many more options here.
}
function doTheMenu()
print("Welcome to Spyder's Factory")
print("")
print("What would you like to make?")
local n = 1
local l = #m - 1
while true do --This while loop may or may not be relevant to the question, it's the menu
term.clear() --this is ComputerCraft lua, the term function is defined
term.setCursorPos(1,2) --elsewhere in an API
for i, j in pairs(m) do
if i == n then
if i < 10 then print(i, " ["..j.opt.."]") else print(i, " ["..j.opt.."]") end
fsel = j.cmd --set fsel to the function name I require in case of a break
tsel = j.opt --Ditto, tsel, human-friendly name
else
if i < 10 then print(i, " "..j.opt) else print(i, " "..j.opt) end
end
end
local a, b = os.pullEvent("key")
if b == 200 and n > 1 then n = n - 1 end
if b == 208 and n <= l then n = n + 1 end
if b == 28 then break end
end
write("\nSure, how many "..tsel.."? ")
qty = tonumber(read())
req[fsel] = req[fsel] + qty
str = fsel.."("..qty..")"
print("Loading function '"..fsel.."("..qty..")'") --Returns "Loading function 'solarPanel(1)'"
func = loadstring(str)
print(func) --Returns "function: 2cdfc5a7"
print("Loading function")
func() --The error line, Returns "string:1: attempt to call nil"
--tellUserWhatNeed()
--makeItHappen()
end
doTheMenu()
The issue is the code fails to run with the error:
string:1 attempt to call nil
Also what is term variable, if that's all your code, term is not defined and is null)
That said: either _G[fsel] is nil or fsel is nil ?
Are you sure you have function declared in _G with the name stored in fsel?
e.i. call before the problem line print (_G[fsel]) to see what it gives you.
This was the solution that ended up working:
local f = loadstring(str)
if f then
setfenv(f, getfenv())
f()
end
This replaces the lines above:
print("Loading function '"..fsel.."("..qty..")'")
func = loadstring(str)
print(func)
print("Loading function")
func()
As well as adding basic error handling for loading the function

Resources