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

How to wait until datastore finished loading?

Asked by 3 years ago

Hello,

I have this script that is supposed to multiply the value of "SpeedLevel" (an int value) by 3 and add that to the player's WalkSpeed as soon as the player joins the game. The problem is that the datastore with the "SpeedLevel" is never done loading...

Here is my script, located in StarterScriptService.

game.Players.PlayerAdded:Connect(function(player)
    local Character = player.Character or player.CharacterAdded:Wait()
    local SpeedLevel = player.InfoFolder.SpeedLevel
    local WalkSpeed = Character.Humanoid.WalkSpeed

    print(SpeedLevel.Value) -- Prints 0, but if the datastore was fully loaded it would print 5


    WalkSpeed = WalkSpeed + (SpeedLevel.Value*3)
end)

Thank you!

1 answer

Log in to vote
1
Answered by
extrorobo 104
3 years ago

this is the premium benefits code for people to get more walkspeed, max health, and jump power. this code only works for premium people but as you can see EnumMembershipType.None so now people with no member ship can use it.

local Players = game:GetService("Players") Players.PlayerAdded:connect(function(player)

if player.MembershipType == Enum.MembershipType.None then
    player.CharacterAdded:connect(function(char)
        local humanoid = char:findFirstChild ("Humanoid")
        if humanoid then
            humanoid.MaxHealth = 1000
            humanoid.Health = humanoid.MaxHealth
            humanoid.WalkSpeed = 200
            humanoid.JumpPower = 100
            local confetti = Instance.new("Sparkles", char:findFirstChild("HumanoidRootPart"))
        end
    end)
end 

end)

Ad

Answer this question