Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I finish my location saving/loading script?

Asked by 5 years ago

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>'
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 TheWaterFoox 255 — 5y
0
nvm someone already did. TheWaterFoox 255 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
I keep getting an error at line 3, sorry it took so long to respond I was trying to figure out the error WyattagumsBackUp 5 — 5y
Ad

Answer this question