Jump to content

[Help] GiveWeapon


brocky

Recommended Posts

I was trying to make a weapon shop gui. When you click the button1 it will give you weapon but the problem is i don't get weapon.

  
if button1 == source then 
 x = getPlayerMoney(source) 
  
if x >= 60000 then 
  triggerServerEvent("shotgun", root )  
  giveWeapon( root, 27, 100 )  
 outputChatBox("You successfully bought a Combat Shotgun") 
  
else  
outputChatBox("You don't have enough cash") 
  
end  
   end  
     end 
addEventHandler( "onClientGUIClick", button1, shotGun, false ) 
  
  

Link to comment
Can you give me a brief example? Because I didn't actually got what you said about the root function.

I understood that it will give the weapon to all player, but how to prevent that? How so?

Change the argument 'root' to your player. And your function giveWeapon is only server-side function. But you're trying to get it work on the client.

Link to comment

The first argument of giveWeapon is who you want to give the weapon to. By default, root means all elements, everywhere. However, in the case of this function (giveWeapon), if you use root, since it is every element, it will only trigger on the player elements (which can be visualized in the element tree). You can put any other player argument in there. I could put:

giveWeapon(getPlayerFromName("Noki"), 27, 100) -- Gives it to a player with the name of 'Noki' 
-- or 
giveWeapon(getRandomPlayer(), 27, 100) -- Gives it to one randomly selected player 
-- or 
giveWeapon(root, 27, 100) -- Gives it to every player 

Link to comment

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...