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

Why does this script does not get player.Character?

Asked by 5 years ago
local ds = game:GetService("DataStoreService"):GetDataStore("MySpeed")

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

local key = "Speed-"..player.UserId

local folder = player:WaitForChild('leaderstats')

local int = Instance.new("IntValue",folder)

int.Name = "?Speed?"

int.Value = 16

local save = ds:GetAsync(key)

if save then

int.Value = save

end

repeat

int.Changed:Connect(function()

ds:SetAsync(key,int.Value)

end)

wait(15)

until player == nil

if player.Character then

warn("Character!")

player.Character.Humanoid.WalkSpeed = int.Value

end

game.Players.PlayerRemoving:Connect(function()

ds:SetAsync(key,int.Value)

end)

end)

Sorry for B A D I N D E N T A T I O N, #StackEdit did this. It Runs :GetAsync(It gets the data) but my Humanoid WalkSpeed doesn't increase. Even though I get speed. [and I also did the CharacterAdded method.]

Please do not post 'Bad Indentation' in the comments. Any Ideas?

0
P.S. This is a script in ServerScriptService tree_tree00 48 — 5y
0
jesus this indentation is worse then ww2 LoganboyInCO 150 — 5y
0
btw use player.CharactedAdded:Connect(function(char) LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I think your problem lies here. You do not need this repeat or wait(15), the .Changed event will always stay connected to the function until you disconnect it. Furthermore player will never be nil so your script will never get to the character part.

repeat
    int.Changed:Connect(function()
        ds:SetAsync(key,int.Value)
    end)
    wait(15)
until player == nil

All you really need to do is edit the above to look more like this,

int.Changed:Connect(function()
    ds:SetAsync(key,int.Value)
end)

-- Character stuff here
Ad

Answer this question