Jump to content

Moving Object (Nil Value)


Recommended Posts

Posted

Hey,

Im making a remote that will open gates by pressing a button...

This is part of my code, when i use it and press the 'gate 1' button, it gives me an errors saying attempt to index global 'movingGates' (a nil value)

Heres my code

local resX, resY = guiGetScreenSize() 
gate1 = createObject ( 971, 96.736, 1918.352, 20.694, 0, 0, 270.40 ) 
  
function makeJobGUI() 
end 
    jobWindow = guiCreateWindow(resX/2-150,resY/2-200,250,350,"Military Gate Remote - Standard",false) 
    guiSetVisible(jobWindow,false) 
    closeButton = guiCreateButton(0.53,0.85,0.40,0.12,"Close",true,jobWindow) 
    addEventHandler("onClientGUIClick",closeButton,function() guiSetVisible(jobWindow,false) showCursor(false) end) 
    gate1Button = guiCreateButton(0.08,0.10,0.40,0.12,"Main Gate",true,jobWindow) 
    addEventHandler("onClientGUIClick",gate1Button,function() if movingGates[source] then return end  movingGates[source] = true moveObject(gate1, 700, 971, 96.736, 1900.352, 20.694, 0, 0, 270.4)         playSoundFrontEnd(hitElement, 5) end) 

I cant get it working, could some one help me, after all i am ron burgandy...

Posted

The error is right, where is the table movingGates? Is it needed for something? Your script could work if you remove the if-then-else or create the table.

I notice you mix serverside and clientside code in this. When clicking the button you should do a triggerServerEvent to move the gate serverside (unless you want it clientside). playSoundFrontEnd doesnt need hitElement when it's clientside.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...