|
| 18 Jan 2016 08:25 PM |
Hey guys, I have a quick question.
I have a global script (server script) in StarterPack and in this script i have a variable called local sessionData
it is an array of items, such as Gold, and Level. However, when the player dies, it seems to reset the script. This is not good for me because i have to get the data from data store, but i dont want to get it again right after a death because it will spam too many requests. Basically i want a global script to keep attached to the player even after death. |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:29 PM |
server script in serverscriptservice
game.Players.PlayerAdded:connect(function(player) -- leaderstats here end) |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:32 PM |
| Put it in game.StarterPlayer.StarterPlayerScripts instead |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:33 PM |
| I tried to place it in StarterPlayerScripts, but server scripts wont run. I added a print statement on the 1st line and it would never show |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:37 PM |
| If I add the script in serverscriptservice, how would i know exactly which player the script holds the data to? Should i use an array of session datas and retrieve the session data from the array (which would require me to look up the index on the array and find it, which might not be most efficient). Or would my serverscriptservice have a script for each player, differentiated by their names? (e.g. xNitroSpeedxScript, [Player]Script) |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:39 PM |
@nitro ...the parameter player. You could make the leaderstats code in the same script as the datastore which is what I do and what I've seen others do |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:44 PM |
My mistake I didn't realize it did not run server scripts
local statScripts = Instance.new("Folder", game:getService("ServerScriptService")) statScripts.Name = "statScripts"
game.Players.PlayerAdded:connect(function(player) local stats = script.statScript:clone() stats.Parent = statScripts stats.localPlayer.Value = player stats.Disabled = false end)
Put the stat script you want to not reset on death inside this script, disable it, and name it 'statScript' and put a object value in it named localPlayer. |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:46 PM |
| AH ok. Sorry about that, I've totally forgotten about Leaderstats. How about sensitive data that you don't want the player to see in the leaderboard? |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:47 PM |
| Name it anything other than "leaderstats". I always store stats in a folder called statnumbers |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:47 PM |
| Use my example or one like it for sensitive data. |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:48 PM |
'Name it anything other than "leaderstats". I always store stats in a folder called statnumbers'
You should store it in ServerScriptService instead |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:51 PM |
| Thank you both, I think I have my solution now. Anyhow, quick question: are server scripts in the workspace visible to the player? Can a hacker look inside a server script inside the workspace? Get data from it? If so, I think i should store most of my scripts in ServerScriptStorage |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:54 PM |
Yes thats the purpose of serverScriptStorage
Anything in workspace is replicated. |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 08:56 PM |
| Ohhh ok, for some reason i thought server scripts in Workspace would be completely untouchable. Thanks, I will store my data in the ServerScriptService |
|
|
| Report Abuse |
|
|
| |
|
|
| 18 Jan 2016 09:02 PM |
Notice serverScriptService appears empty to the client.
https://www.youtube.com/watch?v=bBqD8YgVxDs&feature=youtu.be |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2016 09:24 PM |
| haha, thanks man. Appreciate the effort of creating the video! |
|
|
| Report Abuse |
|
|