_RuiGy Posted November 2, 2012 Share Posted November 2, 2012 Hi, I am trying to make a script to save how much pizzas the player found. But i am getting some errors. This is my code: --server-side function onPlayerQuit() local playerAccount = getPlayerAccount(source) if (playerAccount) then for iii = 1, #nPizzaFound do setAccountData(playerAccount, "xtreme.pizza" .. iii, nPizzaFound[iii]) end end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) function onPlayerLogin() local playerAccount = getPlayerAccount(source) if (playerAccount) then for iii = 1, #nPizzaFound do local playerPizzas = getAccountData(playerAccount, "xtreme.pizza" .. iii) if (playerPizzas) then nPizzaFound[iii] = playerPizzas end end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) nPizzaFound is definied in cliente-side --cliente-side local nPizzaPickup = { createPickup ( -1088.5999755859, 428.20001220703, 13.60000038147, 3, 1582 ), createPickup ( -1067.5, 407.20001220703, 13.60000038147, 3, 1582 ) } -------------------------------------------------------------------------------------- nPizzaFound = {} local nTotalFound = 0 --------------------- function createPizzaPickup ( ) outputChatBox ( "Find the pizzas!" ) end addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), createPizzaPickup ) -------------------------------------------------------------------------------------------------------------- function onPlayerPickupPizza ( thePickup ) for iii = 1, #nPizzaPickup do if thePickup == nPizzaPickup[iii] then if nPizzaFound[iii] == true then outputChatBox ( "You already found this pizza." ) return true end outputChatBox ( "You found the pizza " .. iii .. ". Here, have some money." ) givePlayerMoney ( 500 ) nPizzaFound[iii] = true nTotalFound = nTotalFound + 1 if nTotalFound == #nPizzaFound then outputChatBox ( "Congratulations! You found all pizzas. Here, have more money." ) givePlayerMoney ( 1500 ) end end end end addEventHandler ( "onClientPlayerPickupHit", localPlayer, onPlayerPickupPizza ) and this is the error i am facing: findPizzaMG_S.lua:5: attempt to get length of global 'nPizzaFound' (a nil value) Thanks for any help. Link to comment
myonlake Posted November 2, 2012 Share Posted November 2, 2012 nPizzaFound isn't getting moved to server-side over there, it stays client-side. I have been facing the same problem for months and I don't get how people fix it. Wait for someone to give you tips, I'll be waiting as well. Link to comment
DiSaMe Posted November 2, 2012 Share Posted November 2, 2012 To transfer the data between client and server, you need to use: setElementData or triggerClientEvent triggerServerEvent But I don't see any reason why you would need to use client-side script at all in this case. Setting money client-side does not change it server-side. Link to comment
_RuiGy Posted November 2, 2012 Author Share Posted November 2, 2012 To transfer the data between client and server, you need to use: setElementData or triggerClientEvent triggerServerEvent But I don't see any reason why you would need to use client-side script at all in this case. Setting money client-side does not change it server-side. Thank you, i changed my script to server-side. It works now. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now