Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I finish my location saving/loading script?

So I'm trying to create a position saving/loading script but I keep running into errors

If I make the script like this:

game.Players.PlayerAdded:connect(function(p)

p.CharacterAdded:connect(function(c)

p.Character:moveTo(p:WaitForChild('leaderstats'):WaitForChild('LastLocation').Value)

print('locationloaded')

end)

p.CharacterAdded:connect(function(c)

repeat

wait(0.5)

p.leaderstats.LastLocation.Value = p.Character.HumanoidRootPart.Position

print('locationsaved')

until 1 == 0

end

I get the following error:

ServerScriptService.AutosavingLocation.PlayerJoined/PlayerLeft:12: ')' expected (to close '(' at line 6) near '<eof>'

Else if I add a ")" the end

game.Players.PlayerAdded:connect(function(p)

p.CharacterAdded:connect(function(c)

p.Character:moveTo(p:WaitForChild('leaderstats'):WaitForChild('LastLocation').Value)

print('locationloaded')

end)

p.CharacterAdded:connect(function(c)

repeat

wait(0.5)

p.leaderstats.LastLocation.Value = p.Character.HumanoidRootPart.Position

print('locationsaved')

until 1 == 0

end)

I get the following error:

ServerScriptService.AutosavingLocation.PlayerJoined/PlayerLeft:12: 'end' expected (to close 'function' at line 1) near '<eof>'

2 comments

0

You got three functions. You gotta close all of em' eventually. That's why you need two end) at the end. I'll rewrite the script so it'll be easier to see. :D

0

nvm someone already did.

1 answer

✓ Accepted answer

You are not closing the first function, add one more end) at the end of the script:

game.Players.PlayerAdded:connect(function(p) 
    p.CharacterAdded:connect(function(c)
	    p.Character:moveTo(p:WaitForChild('leaderstats'):WaitForChild('LastLocation').Value)  
	    print('locationloaded')  
    end) 
	    
    p.CharacterAdded:connect(function(c) 
	    repeat
    	    wait(0.5)
    	    p.leaderstats.LastLocation.Value = p.Character.HumanoidRootPart.Position   
    	    print('locationsaved')   
	    until 1 == 0
    end)
end)

Use indent (pressing Tab) to organize you Script lines to avoid issues like that.

1 comment

0

I keep getting an error at line 3, sorry it took so long to respond I was trying to figure out the error

This discussion is preserved as it was. New answers, comments, and votes are closed.