Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this script does not get player.Character?

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?

3 comments

0

P.S. This is a script in ServerScriptService

0

jesus this indentation is worse then ww2

0

btw use player.CharactedAdded:Connect(function(char)

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.