Looking for ways to change a Humanoid's WalkSpeed on the server

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to change the WalkSpeed of players on my game.

  1. What is the issue? Include screenshots / videos if possible!

The problem is whenever the server tries to change the Humanoid’s walkspeed, nothing happens.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • I tried asking the AI assistant.
AI Code
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:FindFirstChild("Humanoid")
        humanoid.WalkSpeed = 25
    end)
end)
  • I tried testing in another studio.
Random Code
for i,player in game.Players:GetPlayers() do
	player.Character.Humanoid.WalkSpeed = 10000
end
  • I reviewed my code and checked for any errors.
My Code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Events = ReplicatedStorage.Events
local Functions = ReplicatedStorage.Functions
local itemRoller = workspace.ItemRoller
local numberOfBoxes = #ServerStorage.Particles:GetChildren()
local box0 = itemRoller.Box0
--Shop Creation
for i = 1,numberOfBoxes-1,1 do
	local box = box0:Clone()
	box:PivotTo(box0.PrimaryPart.CFrame * CFrame.new(0,0,-16*i))
	box.Name = "Box"..i
	box.Parent = itemRoller
end

for i,particle in ServerStorage.Particles:GetChildren() do
	if particle then
		local newParticle = particle:Clone()
		newParticle.CFrame = itemRoller["Box"..i-1].Hitbox.CFrame
		newParticle.Parent = itemRoller["Box"..i-1]
	end
end
--player
Events.EnterExit.OnServerEvent:Connect(function(player,signal)
	if player then
		if signal == "Unenable" then
			player.Character.Humanoid.WalkSpeed = 0
			player.InShop.Value = true
		elseif signal == "Enable" then
			player.Character.Humanoid.WalkSpeed = 16
			player.InShop.Value = false
		end
	end
end)
--Invokes
Functions.RequestInformation.OnServerInvoke = function(player,signal,currentBox)
	if signal == "Buying" then
		local particleName
		for _,comp in itemRoller[currentBox]:GetDescendants() do
			if comp:IsA("Attachment") then
				particleName = comp.Parent.Name
			end
		end
		local information = ServerStorage.PlayerRewards[particleName].Information
		if player.leaderstats.Spirits.Value >= information:GetAttribute("Price") and not ServerStorage.PlayerData[player.Name]:FindFirstChild(particleName) then
			local playerItem = ServerStorage.PlayerRewards[particleName]:Clone()
			playerItem.Parent = ServerStorage.PlayerData[player.Name]

			local newAttachment = ServerStorage.PlayerRewards[particleName]:FindFirstChild(particleName):Clone()
			newAttachment.Parent = player.Character.HumanoidRootPart
			
			local equippedItem = player.Character.HumanoidRootPart:FindFirstChild(player.Equipped.Value)
			if equippedItem then
				equippedItem:Destroy()
			end
			
			player.leaderstats.Spirits.Value -= information:GetAttribute("Price")
			player.Character.Humanoid.WalkSpeed = information:GetAttribute("Speed")
			player.Equipped.Value = particleName
			return "Success"
		elseif player.leaderstats.Spirits.Value < information:GetAttribute("Price")then
			print("Error")
		elseif ServerStorage.PlayerData[player.Name]:FindFirstChild(particleName) and not player.Character.HumanoidRootPart:FindFirstChild(particleName) then
			local newAttachment = ServerStorage.PlayerRewards[particleName]:FindFirstChild(particleName):Clone()
			player.Character.HumanoidRootPart[player.Equipped.Value]:Destroy()
			newAttachment.Parent = player.Character.HumanoidRootPart
			player.Character.Humanoid.WalkSpeed = information:GetAttribute("Speed")
			player.Equipped.Value = particleName
			return "Equippable"
		end
	elseif signal == "Scrolling" then
		local particleName
		for _,comp in itemRoller[currentBox]:GetDescendants() do
			if comp:IsA("Attachment") then
				particleName = comp.Parent.Name
			end
		end
		local spirits = {}
		for i, spirit in pairs(game.ServerStorage.PlayerData[player.Name]:GetChildren()) do
			table.insert(spirits,spirit.Name)
		end
		local rootParticle = player.Character.HumanoidRootPart:FindFirstChild(particleName)
		if rootParticle and table.find(spirits,particleName) then -- They have it equipped and they have it
			return "Equipped"
		elseif table.find(spirits,particleName) and not rootParticle then --They don't have it equipped but they do have it
			return "Exists"
		elseif not table.find(spirits,particleName) and not rootParticle then
			return "Else"
		end
	elseif signal == "ShowInformation" then
		local particleName
		for _,comp in itemRoller[currentBox]:GetDescendants() do
			if comp:IsA("Attachment") then
				particleName = comp.Parent.Name
			end
		end
		local information = ServerStorage.PlayerRewards[particleName].Information
		return {particleName,information:GetAttribute("Price"),information:GetAttribute("Speed")}
	end
end

There are some lines in my code which attempt to change the speed of the player when they purchase an item.

try pasting this into an empty baseplate (or anywhere) and it should change the walkspeed on the server just fine. (it belongs in ServerScriptService)

local player_service = game:GetService("Players")
local desired_humanoid_walkspeed = 30

-- simple function that checks to see if there is a humanoid inside of the player's character
-- if there is one, change the speed.
function on_player_join(plr:Player)
	plr.CharacterAdded:Connect(function(character)
		if character:FindFirstChildWhichIsA("Humanoid") then
			print("humanoid found for", plr.Name)
			character:FindFirstChildWhichIsA("Humanoid").WalkSpeed = desired_humanoid_walkspeed
		end
	end)
end

-- fire every time a player is added
player_service.PlayerAdded:Connect(on_player_join)
1 Like

Sorry I forgot to say that I solved this, I accidentally was setting the humanoids walkspeed in another piece of code.

oh. no worries, it’s all good.

charactersssssssssss

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.