- What do you want to achieve? Keep it simple and clear!
I’m trying to change the WalkSpeed of players on my game.
- What is the issue? Include screenshots / videos if possible!
The problem is whenever the server tries to change the Humanoid’s walkspeed, nothing happens.
- 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.