iPwnza
|
  |
| Joined: 13 Oct 2011 |
| Total Posts: 6139 |
|
|
| 14 Oct 2012 11:33 PM |
I'm trying to make a script that saves your position on the map and then loads it when you join the game. I've succeeded in making the concept (Basic "Force Save" and "Force Load" buttons), but now I want to make it autosave. I was just using OnPlayerEntered to auto-load, and a script to save when the player leaves. The problem is, however, that I have an intro screen for my game that requires the character to respawn after the player has selected the nation that he/she wants to play as. If I make a script that triggers the loading of the data after a button for one of the teams is picked, it just tries to load but fails because the player respawns after it loads. If I add a wait to it, then it waits until the player respawns and then stops waiting. I am looking for a solution to make the script automatically save and load.
NOTE: I DO NOT WANT IT TO LOAD YOUR PREVIOUS POSITION WHEN YOU RESPAWN, JUST IF YOU ENTER/LEAVE THE GAME!
Here are my scripts:
Save:
script.Parent.MouseButton1Down:connect(function()
if script.Parent.Parent.Parent.Parent.DataReady == true then
player = script.Parent.Parent.Parent.Parent player:SaveNumber("posX", player.Character.Torso.Position.X) player:SaveNumber("posY", player.Character.Torso.Position.Y) player:SaveNumber("posZ", player.Character.Torso.Position.Z)
-- This part just pushes a notification out to my GUI. Ignore this.
script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "You have forced a save." script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(0, 0, 0.2, 0)) wait (5) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(-1, 0, 0.2, 0)) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "+100 K$"
else
script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "Error: DataReady is not true." script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(0, 0, 0.2, 0)) wait (5) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(-1, 0, 0.2, 0)) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "+100 K$" end end)
LOAD:
script.Parent.MouseButton1Down:connect(function()
if script.Parent.Parent.Parent.Parent.DataReady == true then
player = script.Parent.Parent.Parent.Parent player.Character.Torso.CFrame = CFrame.new(Vector3.new(player:LoadNumber("posX"), player:LoadNumber("posY"), player:LoadNumber("posZ")))
-- ONCE AGAIN JUST TO PUSH A NOTIFICATION TO MY GUIS
script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "You have forced a load." script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(0, 0, 0.2, 0)) wait (5) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(-1, 0, 0.2, 0)) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "+100 K$"
else
script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "Error: DataReady is not true." script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(0, 0, 0.2, 0)) wait (5) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K:TweenPosition(UDim2.new(-1, 0, 0.2, 0)) script.Parent.Parent.Parent.MainUI.TopBar.Frame.K.Text = "+100 K$"
end end) |
|
|
| Report Abuse |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
iPwnza
|
  |
| Joined: 13 Oct 2011 |
| Total Posts: 6139 |
|
|
| 15 Oct 2012 07:00 AM |
@Cnt
What? Can't even find anything about that on the wiki... |
|
|
| Report Abuse |
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 15 Oct 2012 07:56 AM |
He meant PlayerAdded, And any basic scripter knows about playeradded t_T |
|
|
| Report Abuse |
|
|
| 15 Oct 2012 09:42 AM |
function save(player) player:WaitForDataReady() player:SaveNumber("posX", player.Character.Torso.Position.X) player:SaveNumber("posY", player.Character.Torso.Position.Y) player:SaveNumber("posZ", player.Character.Torso.Position.Z) end
function load(player) player:WaitForDataReady() player.Character.Torso.CFrame = CFrame.new(Vector3.new(player:LoadNumber("posX"), player:LoadNumber("posY"), player:LoadNumber("posZ"))) -- I suggest using Character:MoveTo(Position) instead of CFraming end
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:wait() -- spawn once p.CharacterAdded:wait() -- spawn twice load(p) end)
game.Players.PlayerRemoving:connect(save) |
|
|
| Report Abuse |
|