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

Position sets itself to 0 with player.Character.HumanoidRootPart.Position?

Asked by 6 years ago

Problem is with my new datastore script the position doesn't get set to the players position if they have never loaded before, wich ends in a 0,0,0 position wich ends in falling of the map... Here is the script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = game:GetService("DataStoreService")
local PositionSave = DataStore:GetDataStore("PlayerSave2")
local spawnPos = workspace:WaitForChild("SpawnPos")

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

    local PlayerStats = player:WaitForChild("PlayerStats")
    local Pos = Instance.new("Vector3Value",player.PlayerStats)
    Pos.Name = "PlayerPosition"

    Pos.Value = PositionSave:GetAsync(player.UserId) or player.Character.HumanoidRootPart.Position  
    PositionSave:SetAsync(player.UserId, Pos.Value)

    Pos.Changed:connect(function()
        PositionSave:SetAsync(player.UserId, player.Character.HumanoidRootPart.Position)
    end)

    game.Players.PlayerRemoving:connect(function(player)
        PositionSave:SetAsync(player.UserId, player.PlayerStats.PlayerPosition.Value)
    end)    

end)
0
Try pre-setting the position value to something if they've never loaded before? SmugNyan 24 — 6y

Answer this question