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

Is somthing wrong with this script?

Asked by 10 years ago

Hi, thanks for taking time to read this. I finished a script that is suppose to detect if a player has a certain gamepass when they enter, and then load up their previous position saved if so. If they do but have not played before, it will return a value in which will get loaded into the HumanoidRootPart's position so they will get teleported. If they do not have the pass, it will do the same as mentioned previously, return a position value. since Character Auto-Loading is turned off, it will take the value and load it into HumPos, which is defining the HumanoidRootPart. There will be checkpoints around the map that have a script in it so when touched, it will save the HumanoidRootPart's position at the time of touched to a Data Store if the player owns the pass. This script also handles respawning. I tested this in another place with the passId set to the id of a hat I own just to see if it would work. However it didn't, and I have a feeling I did something wrong I just dont know what. Thanks for reading all of this, and here is the script.

local passId = 000000
local DataStore = game:GetService("DataStoreService"):GetDatStore("PlayerPos")
local respawnTime = 5

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

    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,passId) then
        local Value = DataStore:GetAsync("Position")
        if Position then
            return Position
        else
            return -151.4, 36.5, -138
        end     


        plr.CharacterAdded:connect(function(Character)
            HumPos = Character:FindFirstChild("HumanoidRootPart")
            local Humanoid = Character:FindFirstChild("Humanoid") -- find the humanoid, and detect when it dies
            if Humanoid then
                Humanoid.Died:connect(function()
                    wait(respawnTime) -- delay, then respawn the character
                    plr:LoadCharacter()
                end)
            end
        end)

        plr:LoadCharacter()
        local HumPos = Value

    else
        local function UpdateData(key)
            return -151.4, 36.5, -138
        end
        DataStore:UpdateAsync("Position", UpdateData)

        wait(1)     

        plr:LoadCharacter()
        local HumPos = key
    end
end)

By the way this is also in a regular script, not a local script. I also changed the name of the data store from PlayerPos to ATestStore at the time of testing this script. It was not tested in solo. When I tested it, it should have moved me to position -151.4, 36.5, -138, but it didn't. Am I doing something wrong here? Thanks again for reading all this and... well thanks!

1 answer

Log in to vote
0
Answered by
SimIcy 5
10 years ago

Hello, on line 12 you didn't set the players "Humanoid or character to be moven."

Here's an example Note this will not work i don't always feed the answer i help them learn

local passId = 000000
local DataStore = game:GetService("DataStoreService"):GetDatStore("PlayerPos")
local respawnTime = 5

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

    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,passId) then
        local Value = DataStore:GetAsync("Position")
        if Position then
            return Position
        else
            local torso = dfesf.Torso
           local move = {mov.Position}
           torso.CFrame = CFrame.new(-151.4, 36.5, -138) 

        end     


        plr.CharacterAdded:connect(function(Character)
            HumPos = Character:FindFirstChild("HumanoidRootPart")
            local Humanoid = Character:FindFirstChild("Humanoid") -- find the humanoid, and detect when it dies
            if Humanoid then
                Humanoid.Died:connect(function()
                    wait(respawnTime) -- delay, then respawn the character
                    plr:LoadCharacter()
                end)
            end
        end)

        plr:LoadCharacter()
        local HumPos = Value

    else
        local function UpdateData(key)
            return -151.4, 36.5, -138
        end
        DataStore:UpdateAsync("Position", UpdateData)

        wait(1)     

        plr:LoadCharacter()
        local HumPos = key
    end
end)

0
Could you explain? Because return should return that value to position shouldnt it? AwsomeSpongebob 350 — 10y
0
Here is an example it will not work but will give you a idea. SimIcy 5 — 10y
0
I think I get it now. Thanks! (Btw I just realized I didn't do HumPos.Position XD) AwsomeSpongebob 350 — 10y
Ad

Answer this question