Saving Speed and Jump finally works but I dont move

Hey! I finally was able to make it so it saves walkSpeed and JumpPower, but it won’t work for new players that have a CurrentSpeed and CurrentJump of 0. I tried making something that makes it 16 and 50 default value but it won’t work. The output claims that: "Line 104: attempt to index nil with ‘Changed’ " . Here is the script: (I put a note on Line 104)

local ServerStorage = game:GetService("ServerStorage")
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")

local AUTOSAVE_INTERVAL = 60

local VIPid = 9456079

game.Players.PlayerAdded:Connect(function(player)
	
	local character = player.Character
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = leaderstats
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = leaderstats
	
	local Activations = Instance.new("IntValue")
	Activations.Name = "Activations"
	Activations.Parent = leaderstats
	
	local Deaths = Instance.new("IntValue")
	Deaths.Name = "Deaths"
	Deaths.Parent = leaderstats
	
	local Upgrades = Instance.new("Folder")
	Upgrades.Name = "Upgrades"
	Upgrades.Parent = player
	
	local SpeedLevel = Instance.new("IntValue")
	SpeedLevel.Name = "SpeedLevel"
	SpeedLevel.Parent = Upgrades

	local JumpLevel = Instance.new("IntValue")
	JumpLevel.Name = "JumpLevel"
	JumpLevel.Parent = Upgrades
	
	local maxSpeed = Instance.new("IntValue")
	maxSpeed.Name = "maxSpeed"
	maxSpeed.Parent = player
	
	local maxJump = Instance.new("IntValue")
	maxJump.Name = "maxJump"
	maxJump.Parent = player

	local CurrentSpeed = Instance.new("IntValue")
	CurrentSpeed.Name = "CurrentSpeed"
	CurrentSpeed.Parent = player
	
	local CurrentJump = Instance.new("IntValue")
	CurrentJump.Name = "CurrentJump"
	CurrentJump.Parent = player

	local Multiplier = Instance.new("NumberValue")
	Multiplier.Name = "Multiplier"
	Multiplier.Parent = player
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPid) then
		Multiplier.Value = 1.5
	else
		Multiplier.Value = 1
	end

	-->> Data: Begining
	
	local playerUserId = "Player_"..player.UserId
	
	-->>Data: Load Data
	
	local data
	local success, errormessage	 = pcall(function()
		data = myDataStore:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
			Points.Value = data.Points
			Wins.Value = data.Wins
			Activations.Value = data.Activations
			Deaths.Value = data.Deaths
			SpeedLevel.Value = data.SpeedLevel
			JumpLevel.Value = data.JumpLevel
			maxSpeed.Value = data.maxSpeed
			maxJump.Value = data.maxJump
			CurrentSpeed = data.CurrentSpeed
			CurrentJump = data.CurrentJump
			Multiplier = data.Multiplier
		else
			CurrentSpeed = 16
			CurrentJump = 50
		end
	end
	
	player.CharacterAdded:Connect(function()
		player.Character.Humanoid.WalkSpeed = player.CurrentSpeed.Value
		player.Character.Humanoid.JumpPower = player.CurrentJump.Value
		
		player.Character.Humanoid.WalkSpeed.Changed:Connect(function() -- LINE 104
			player.CurrentSpeed.Value = player.Character.Humanoid.WalkSpeed.Value
		end)
		player.Character.Humanoid.JumpPower.Changed:Connect(function() -- LINE 107
			player.CurrentJump.Value = player.Character.Humanoid.JumpPower.Value
		end)
	end)
	
end)

-->> Data: Saving Stats

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId

	local data = {
		Points = player.leaderstats.Points.Value;
		Wins = player.leaderstats.Wins.Value;
		Activations = player.leaderstats.Activations.Value;
		Deaths = player.leaderstats.Deaths.Value;
		SpeedLevel = player.Upgrades.SpeedLevel.Value;
		JumpLevel = player.Upgrades.JumpLevel.Value;
		maxSpeed = player.maxSpeed.Value;
		maxJump = player.maxJump.Value;
		CurrentSpeed = player.CurrentSpeed.Value;
		CurrentJump = player.CurrentJump.Value;
		Multiplier = player.Multiplier.Value;
	}
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(playerUserId, data)
	end)
		
	if success then
		print("Data succefully saved!")
	else
		print("Data saving error")
		warn(errormessage)
	end
	
end)
1 Like

Changed event can only be used in instance, not properties,

player.Character.Humanoid.JumpPower.Changed:Connect(function()
--incorrect
player.Character.Humanoid.Changed:Connect(function()
--correct
2 Likes

Ok. I tried modifing the script and it now says that Line 105 is trying to index number with ‘Value’

	player.CharacterAdded:Connect(function()
		player.Character.Humanoid.WalkSpeed = player.CurrentSpeed.Value
		player.Character.Humanoid.JumpPower = player.CurrentJump.Value
		
		player.Character.Humanoid.Changed:Connect(function()
			player.CurrentSpeed.Value = player.Character.Humanoid.WalkSpeed.Value
			player.CurrentJump.Value = player.Character.Humanoid.JumpPower.Value
		end)
	end)

how would I go about making this work?

1 Like
player.Character.Humanoid.JumpPower.Value

you don’t need value there because it will automatically get the value of the property if it isn’t meant to be defined.

1 Like

Changed shouldn’t even be used for Properties. That is what GetPropertyChangedSignal is for.

script:GetPropertyChangedSignal("Name"):Connect(function()
	print"Name changed."
end)

But I’m sure you already know this.

3 Likes

So I tried expierementing with that, but I can’t seem to figure out how to make it work with WalkSpeed and JumpPower… Do you know what I should do by any chance?

1 Like
Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	print("whos that bad person who changed walkspeed!")
end)
1 Like

Here is an example

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			print("Walk speed changed to "..humanoid.WalkSpeed)
		end)
		
		humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
			print("Jump power changed to "..humanoid.WalkSpeed)
		end)
	end)
end)
1 Like

ummmm. Thats what I had tried a smh it didn’t work…

	player.CharacterAdded:Connect(function()
		player.Character.Humanoid.WalkSpeed = player.CurrentSpeed.Value
		player.Character.Humanoid.JumpPower = player.CurrentJump.Value

		player.Character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			print"Name changed."
		end)
	end)
1 Like

Try to use my code instead of the old code.

2 Likes

Nope… I modified it this way and it didn’t work:

	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid.WalkSpeed = player.CurrentSpeed.Value
		humanoid.JumpPower = player.CurrentJump.Value
		
		humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			print("Walk speed changed to "..humanoid.WalkSpeed)
		end)
		humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
			print("Jump power changed to "..humanoid.WalkSpeed)
		end)
	end)
1 Like

Are you changing it on a Script or LocalScript? Be sure it’s on the server not the client.

1 Like

Its on server, but its still won’t work, and I can’t move either… Here is the full script.

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")

local AUTOSAVE_INTERVAL = 60

local VIPid = 9456079

game.Players.PlayerAdded:Connect(function(player)
	
	local character = player.Character
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = leaderstats
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = leaderstats
	
	local Activations = Instance.new("IntValue")
	Activations.Name = "Activations"
	Activations.Parent = leaderstats
	
	local Deaths = Instance.new("IntValue")
	Deaths.Name = "Deaths"
	Deaths.Parent = leaderstats
	
	local Upgrades = Instance.new("Folder")
	Upgrades.Name = "Upgrades"
	Upgrades.Parent = player
	
	local SpeedLevel = Instance.new("IntValue")
	SpeedLevel.Name = "SpeedLevel"
	SpeedLevel.Parent = Upgrades

	local JumpLevel = Instance.new("IntValue")
	JumpLevel.Name = "JumpLevel"
	JumpLevel.Parent = Upgrades
	
	local maxSpeed = Instance.new("IntValue")
	maxSpeed.Name = "maxSpeed"
	maxSpeed.Parent = player
	
	local maxJump = Instance.new("IntValue")
	maxJump.Name = "maxJump"
	maxJump.Parent = player

	local CurrentSpeed = Instance.new("IntValue")
	CurrentSpeed.Name = "CurrentSpeed"
	CurrentSpeed.Parent = player
	
	local CurrentJump = Instance.new("IntValue")
	CurrentJump.Name = "CurrentJump"
	CurrentJump.Parent = player

	local Multiplier = Instance.new("NumberValue")
	Multiplier.Name = "Multiplier"
	Multiplier.Parent = player
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPid) then
		Multiplier.Value = 1.5
	else
		Multiplier.Value = 1
	end

	-->> Data: Begining
	
	local playerUserId = "Player_"..player.UserId
	
	-->>Data: Load Data
	
	local data
	local success, errormessage	 = pcall(function()
		data = myDataStore:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
			Points.Value = data.Points
			Wins.Value = data.Wins
			Activations.Value = data.Activations
			Deaths.Value = data.Deaths
			SpeedLevel.Value = data.SpeedLevel
			JumpLevel.Value = data.JumpLevel
			maxSpeed.Value = data.maxSpeed
			maxJump.Value = data.maxJump
			CurrentSpeed = data.CurrentSpeed
			CurrentJump = data.CurrentJump
			Multiplier = data.Multiplier
		else
			CurrentSpeed = 16
			CurrentJump = 50
		end
	end
	
	player.CharacterAdded:Connect(function()
		player.Character.Humanoid.WalkSpeed = player.CurrentSpeed.Value
		player.Character.Humanoid.JumpPower = player.CurrentJump.Value

		player.Character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			print"Name changed."
		end)
	end)
	
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid.WalkSpeed = player.CurrentSpeed.Value
		humanoid.JumpPower = player.CurrentJump.Value
		
		humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			print("Walk speed changed to "..humanoid.WalkSpeed)
		end)
		humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
			print("Jump power changed to "..humanoid.WalkSpeed)
		end)
	end)
	
end)

-->> Data: Saving Stats

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId

	local data = {
		Points = player.leaderstats.Points.Value;
		Wins = player.leaderstats.Wins.Value;
		Activations = player.leaderstats.Activations.Value;
		Deaths = player.leaderstats.Deaths.Value;
		SpeedLevel = player.Upgrades.SpeedLevel.Value;
		JumpLevel = player.Upgrades.JumpLevel.Value;
		maxSpeed = player.maxSpeed.Value;
		maxJump = player.maxJump.Value;
		CurrentSpeed = player.CurrentSpeed.Value;
		CurrentJump = player.CurrentJump.Value;
		Multiplier = player.Multiplier.Value;
	}
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(playerUserId, data)
	end)
		
	if success then
		print("Data succefully saved!")
	else
		print("Data saving error")
		warn(errormessage)
	end
	
end)
1 Like

Can’t you just reference the player.CurrentJump.Value to CurrentSpeed.Value?This also goes for CurrentJump

1 Like

CurrentSpeed and CurrentJump are custom made variables in the player, so no, i don’t think i can do that.

I don’t see how you can’t do that, you are just trying to reference it to the created IntValue.

I’m sorry i didnt even test it before answering lol… So sorry i obviously can do that you’re right… I can do that although it doesn’t solve my problem…

Can you print out the Humanoid’s Walkspeed and JumpPower after setting it’s value? Ex:

humanoid.WalkSpeed = player.CurrentSpeed.Value
humanoid.JumpPower = player.CurrentJump.Value
print("Current walkspeed: ".. humanoid.WalkSpeed)
print("Current jumppower: ".. humanoid.JumpPower)
1 Like

Update, @suspectshot108 Probably works, but the problem is in the two lines that load the character’s current speed… The output says line 112 (the one that loads WalkSpeed) "attempt to index Number with “Value” "…

There lies my problem like i just replied… :frowning: