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

I'm having problems with Teleporting and Saving Positions?

Asked by 3 years ago

Hello! So I just testing out my game here, it has pretty old coding. The problem I am having here is trying to load the character position. The scripts are mostly serversided, however the HumanoidRootPart ends up in the correct position, but the Character itself doesn't.

https://cdn.discordapp.com/attachments/791897808571072542/872016735312695306/Problem.mp4

So, the script for loading the position is like this.

wait(5) --The wait delay for when the character spawns so it doesn't create an error.
local playername = script.Parent.Name
local player = game.Players:FindFirstChild(playername)
local char = player.Character
if player.Stats.Died.Value == false then
  char.HumanoidRootPart.Position = Vector3.new(player.Stats.XAxis.Value,player.Stats.YAxis.Value,player.Stats.ZAxis.Value) --I think the problem is this. The game saves the X,Y,Z axis seperately since I really have huge problems datastore saving Vector3's and had many errors trying. I mostly try to rely on youtube tutorials which didn't seem to help.
end
if player.Stats.Died.Value == true or player.Stats.XAxis.Value == 0 and player.Stats.YAxis.Value == 0 and player.Stats.ZAxis.Value == 0 then
    script.Parent.LoadSpawn.Disabled = false --The LoadSpawn script is a simple script that reloads the character and makes sure they respawn at their spawn when they died.
    player.Stats.Died.Value = false --A simple detection if the player has died, if it is true then the player loads back to their spawn. If it is false, they load back to their location.
end
while true do
    wait(1)
    if script.Parent.isDied.Value == false then
        player.Stats.XAxis.Value = char.HumanoidRootPart.Position.X
        player.Stats.YAxis.Value = char.HumanoidRootPart.Position.Y
        player.Stats.ZAxis.Value = char.HumanoidRootPart.Position.Z
    end
    if script.Parent.isDied.Value == true then
        player.Stats.XAxis.Value = 0
        player.Stats.YAxis.Value = 0
        player.Stats.ZAxis.Value = 0
    end
end

I may have the feeling it may be infuriating to read this, or not. But if you can help me please do so!

My suspicions are; It may have to do with it just being a custom character The X,Y,Z being saved seperately

Answer this question