123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
|
| 12 Jul 2014 10:59 AM |
Hey, I was just wondering why this wouldn't work...
[This bit goes into a Script which is then placed in Workspace]
'DS = game:GetService("DataStoreService"):GetDataStore("Spawns") SModel = Workspace.Spawns --Spawns
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) local D = DS:GetAsync(p.userId) if D == nil then DS:SetAsync(p.userId, 1) end local D = DS:GetAsync(p.userId) c:MoveTo(SModel:FindFirstChild(D)) end) end)'
[This goes into a Script in each SpawnLocations, each labeled 1, 2, 3, 4, etc... In the Model 'Spawns']
'DS = game:GetService("DataStoreService"):GetDataStore("Spawns")
script.Parent.Touched:connect(function(h) local plr = game.Players:GetPlayerFromCharacter(h.Parent) if plr then DS:SetAsync(plr.userId, tonumber(script.Parent.Name)) end end)'
-------------------------------------------------------------------------------
I've ran the Top Script and it seems to work fine with no error's in the Output box. But when I run the second script that's in one of the SpawnLocations, (for example I'll run the script in Spawn '2') and I'll get this Error in Output:
'-DS = game:GetService("DataStoreService"):GetDataStore("Spaw:3: attempt to index global 'script' (a nil value) -Stack Begin - Script 'DS = game:GetService("DataStoreService"):GetDataStore("Spaw', Line 3 - Stack End'
Obviously you can't really get an accurate error message seeing as it would only work once touched... But I just need to know why it wont work when I play the game, go to the second spawn, touch it, leave the game, rejoin the game but find that I've started on the original first spawn...
(I'm basically going for a checkpoint system in my RPG)
Thanks in advance |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2014 11:01 AM |
| 'script' isn't defined in the command bar. |
|
|
| Report Abuse |
|
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
|
| 12 Jul 2014 11:12 AM |
Workspace.Spawns.2.ScriptForTouch:6: attempt to index global 'DS' (a nil value) Stack Begin Script 'Workspace.Spawns.2.ScriptForTouch', Line 6 Stack End Disconnected event because of exception |
|
|
| Report Abuse |
|
|
| |
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
|
| 12 Jul 2014 01:02 PM |
I put a quotation mark before the DS and at the end) to make sure you can see that they aren't all one big script...
+ Bump |
|
|
| Report Abuse |
|
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
| |
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
| |
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
|
| 12 Jul 2014 01:28 PM |
| Everyone is SO helpful here today... -.- |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2014 02:58 PM |
Yea, they're aren't actually great at helping sometimes.
Try this;
DS = game:GetService("DataStoreService"):GetDataStore("Spawns") Brick = script.Parent
Brick.Touched:connect(function(h) local plr = game.Players:GetPlayerFromCharacter(h.Parent) if plr then DS:SetAsync(plr.userId, tonumber(Brick.Name)) end end)
I don't see why it would work but give it a try. Maybe someone here'll have a better answer :P |
|
|
| Report Abuse |
|
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
|
| 13 Jul 2014 05:15 AM |
I get this:
- Workspace.Spawns.2.ScriptForTouch:7: attempt to index global 'DS' (a nil value) - Stack Begin - Script 'Workspace.Spawns.2.ScriptForTouch', Line 7 - Stack End - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2014 05:28 AM |
That means DS wasn't set to the DataStore on line 1...
But we clearly set it -_- |
|
|
| Report Abuse |
|
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
|
| 13 Jul 2014 06:29 AM |
| Exactly :/ What could be wrong? :( |
|
|
| Report Abuse |
|
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
| |
|
123happy
|
  |
| Joined: 23 Sep 2008 |
| Total Posts: 23 |
|
| |
|
|
| 14 Jul 2014 08:18 AM |
Try this, I doubt it'll work but at least I'm trying (unlike others)
local DS = game:GetService("DataStoreService"):GetDataStore("Spawns") local Brick = script.Parent
Brick.Touched:connect(function(h) local plr = game.Players:GetPlayerFromCharacter(h.Parent) if plr then DS:SetAsync(plr.userId, tonumber(Brick.Name)) end end) |
|
|
| Report Abuse |
|
|