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 » Scripting Helpers
Home Search
 

Re: Making this save/load script automatic?

Previous Thread :: Next Thread 
iPwnza is not online. 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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 Oct 2012 11:37 PM
Use a playerneted
Report Abuse
iPwnza is not online. 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 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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