generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: After a few weeks, I guess I will go ahead and ask.

Previous Thread :: Next Thread 
windows65 is not online. windows65
Joined: 22 Jun 2009
Total Posts: 86
12 Apr 2015 02:30 PM
Hey fellow ROBLOXIANS, I have been working tirelessly for the past few weeks getting my game ready/scripted for beta stage. Only one problem... I am still relatively new to LUA (Used to C++ - Python) and I need to know how to set "global" variables. I want a variable set to to where when the person dies it does not reset.

I am currently working on a Gun Shop/Inventory system GUI. I have tried to use variables, server storage, etc but nothing is working! I would love to make this with server storage preferably but I just cant get it to work. Currently, when a person buys a gun, it deducts the money, gives the guns/puts them in starter pack. If they choose to buy another gun the same thing happens. Here's the problem, when they die, they have to re-buy their weapon instead of inserting it into their inventory. I am not going to publicly post the script, but here is how it works:
>-----------------------------------<
Player Clicks Buy Gun
\/
If gun is bought put in his inventory
||
Elseif gun is not bought, check money, if all is well take money and insert into inventory.
\/
Wait for another Buy
>-----------------------------------<
The only problem with that is, the Boolean variable I used to check if gun is bought resets upon death.


To summarize what I want, I would like for you to help me add server side storage into these scripts, and maybe even for the money leaderboard. I am not expecting you to code it for me, but an understandable server script is appreciated.

(Yes, I have referred to ROBLOX Wiki, StackOverflow, Set Studio to accept and send to servers, etc.) I just can not get it to work for some reason. Let me know if you have any further questions, i tried to cover it all. Also, if your going to be rude Please take your immaturity elsewhere, Thank you. This topic is for serious developers only. (Constructive criticism accepted though!)
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
12 Apr 2015 02:31 PM
Lua*
Report Abuse
windows65 is not online. windows65
Joined: 22 Jun 2009
Total Posts: 86
12 Apr 2015 02:33 PM
PS. In the sentence, "Here's the problem, when they die, they have to re-buy their weapon instead of inserting it into their inventory." I meant upon clicking the button to choose their class to use, it asks them to buy the gun instead of giving the class when already paid for.
Report Abuse
Proxemics is not online. Proxemics
Joined: 30 Oct 2013
Total Posts: 2542
12 Apr 2015 02:33 PM
^ doesn't matter, it's still the same thing

@op there are free models for this ya know
Report Abuse
windows65 is not online. windows65
Joined: 22 Jun 2009
Total Posts: 86
12 Apr 2015 02:34 PM
Thanks for the correction, I will apply that next time. Lua, not LUA.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
12 Apr 2015 02:37 PM
Use _G

i.e. _G["PlayerOwnsClass_ClassNameHere"] = false

if _G["PlayerOwnsClass"] then
--// give them stuff
else
--// prompt purchase here
_G["PlayerOwnsClass_ClassNameHere"] = true
end
Report Abuse
windows65 is not online. windows65
Joined: 22 Jun 2009
Total Posts: 86
12 Apr 2015 04:24 PM
Thank you for the response, firs off I am going to assume that PlayerOwnsClass is player.userId.

Considering that the case, this can provide a nice temporary fix for the problem.

If anyone is able to help me with the networking part, it would be greatly appreciated!

Here is what I have so far:
(Only Networking)

--Initilization:
-->-------------------------------------------------------------------
classKey = "Assult_"..player.userId
gunStorage = game:GetService("DataStoreService"):GetDataStore(classKey)
-->-------------------------------------------------------------------


--Networking Functions:
-->-------------------------------------------------------------------
function checkBuyStatus()
local buyStatus = gunStorage:GetAsync(classKey)
print("[Success] | Type = Gun | Response: > " .. buyStatus)
return buyStatus

end


function sendBuyReq()
local success, message = pcall(function()
gunStorage:SetAsync(classKey, "true")
print("[Success] | Type = Sent Buy Request | Response: > " .. message)
end)
if not success then
print("[Error] | Type = Gun Network | Response: > " .. message)
end
end
-->-------------------------------------------------------------------


--Begin the actual script here:
-->--------------------------------------------------------------------------------

function onButtonClick()
checkBuyStatus()
if bought == "false" then
takeMoney()
sendBuyReq() --Buys gun then \/
if checkBuyStatus()== "true" then --Checks if the gun was Really bought
giveClass()
else
print("[Buy Unsuccessful] | Request sent but did not go through properly")
end

elseif bought == "true" then --This has already been bought, So give the class.
giveClass(script.Parent)

else
print("Buy Unsuccessful")

end
end
end
end)
-->--------------------------------------------------------------------------------

Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
12 Apr 2015 04:25 PM
Player.StarterGear -- player owns it forever
Report Abuse
windows65 is not online. windows65
Joined: 22 Jun 2009
Total Posts: 86
12 Apr 2015 04:30 PM
In a normal game setup, yes but,
When they choose to equip a new class the starter gear is changed to that class.

I do not think it applys in the "Universe" setup does it? Am i misunderstanding?
[About to do some research]
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
12 Apr 2015 04:33 PM
StarterGear is just what tools the player gets when the character respawns. The only data that carries over to different places in Universe is the ones you store in datastiore
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
12 Apr 2015 04:35 PM
I like you.

Put a value in the Player, or even better in ServerStorage, or even better just in a table.
Report Abuse
windows65 is not online. windows65
Joined: 22 Jun 2009
Total Posts: 86
12 Apr 2015 04:49 PM
StarterGear is just what tools the player gets when the character respawns. The only data that carries over to different places in Universe is the ones you store in datastiore


Okay thought so, That goes back to DataStore, in the code I posted above, I have a section called Networking Functions, now, the checkBuyStatus() function is suppose to check if the gun has been bought before. The sendBuyReq() is suppose to "buy" the gun, in other words make the string "true", I know not proper Boolean. Anyway, you can see in the main program that if the guns not bought i'm requesting to buy the gun, then double checking if the gun was bought if so give the players their stuff.

I am pretty sure the problem lies in the networking functions.
Here are a few errors I am getting from the code:

In this error, it is calling buyStatus a nil value, or empty value.
>------------------------------------------------------------------------------
Attempt to concatenate local 'buyStatus' (a nil value):
Script '...GunShopGUI.Main.Assult.payForGun', Line 40 - global checkBuyStatus
>------------------------------------------------------------------------------



Thank you for saying that eLunate, that was very nice!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image