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

Help with this code please :P?

Asked by
UEm1R 9
6 years ago
Edited 6 years ago

Hello, so this code saves the location when a player leaves so the question is how do I make a script that teleports them to their last location when they're joining?

local DataStore = game:GetService("DataStoreService"):GetDataStore("test")
wait(1)
print(DataStore:GetAsync("last"))
print(DataStore:GetAsync("time"))

local lastPos = Vector3.new(0,0,0)

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterRemoving:Connect(function(char)
        lastPos = char.HumanoidRootPart.Position
    end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    DataStore:SetAsync("last",tostring(lastPos))
    DataStore:SetAsync("time",tostring(tick()))
end)

game:BindToClose(function()
    wait(3)
end)
0
try this: local stats = game.Players.LocalPlayer:WaitForChild("leaderstats"). This will award the XP to the localplayer's leaderstats BloxRoxe 109 — 6y
0
Edit your code and use the blue Lua symbol to generate a block where you can put your code inside. This will make your code formatted so everyone can see it clearly. chomboghai 2044 — 6y
0
BloxRoxe i'm going to try that now ty! chomboghai ty changed it :D UEm1R 9 — 6y
0
Tysm BloxRoxe it's working.. im so dumb that i didn't use LocalPlayer xD UEm1R 9 — 6y

4 answers

Log in to vote
0
Answered by 6 years ago

I added a thing to check if the player has data and if not teleports to spawn.

local DataStore = game:GetService("DataStoreService"):GetDataStore("test")
wait(1)
print(DataStore:GetAsync("last"))
print(DataStore:GetAsync("time"))

local lastPos = Vector3.new(0,0,0)

game.Players.PlayerAdded:connect(function(plr)
    plr.Character.HumanoidRootPart.Position = DataStore:GetAsync(plr.UserId) or Vector3.new() --Put the spawn location position numbers in there
    plr.CharacterRemoving:Connect(function(char)
        lastPos = char.HumanoidRootPart.Position
    end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    DataStore:SetAsync("last",tostring(lastPos))
    DataStore:SetAsync("time",tostring(tick()))
end)

game:BindToClose(function()
    wait(3)
end)
Ad
Log in to vote
0
Answered by
Ap_inity 112
6 years ago

To find a player, just use game.Players.LocalPlayer, easy as that!

0
@Ap_inity it's only working in Roblox Studio and as a Script not as a LocalScript.. help please UEm1R 9 — 6y
0
Then use a script xD Ap_inity 112 — 6y
0
I can't use LocalPlayer with a script UEm1R 9 — 6y
Log in to vote
0
Answered by
AltNature 169
6 years ago
Edited 6 years ago

You can go and play it in game and press F9 to see errors Make it a local script

Log in to vote
0
Answered by 6 years ago

Bro, ehm, i think it works due the fact you can't not use any localscript if it's not a specific player ask why, well because it works like that.

0
Ok and i did got confused Animescapetower 10 — 6y

Answer this question