game.Players.LocalPlayer
will not work on the server; you can only use it in a local script which runs on the client (ServerScriptService is only for server-sided code). The script is also missing a loop, so it will only run once.
Can I just do while true do In the begining and End on the end ?
But when he walks the script fires up again so ?
I feel like you need to strengthen your understandings of basic scripting concepts before tackling larger problems, since in order to advance in your skills you need to have a solid foundation to build off of.
Since nobody is going to spoonfeed the answer as it has been made clear it should be, I guess I will.
Create a script within ServerScriptService named “SpeedScript”.
Within the script, copy & paste this code that I wrote:
local Players = game.Players
local RunService = game:GetService("RunService")
local SpeedPerStud = 0.1 --Configure this to your liking!!!!!
local StudsTraveled = 0
local LastPosition = nil
function playerAdded(player)
--Fires when a player joins the server
local Speed = Instance.new("NumberValue") --In case the player dies, save their speed
Speed.Name = "SpeedValue"
Speed.Value = 16
Speed.Parent = player
local RootPartHeartbeat = nil
player.CharacterAdded:Connect(function(character)
LastPosition = character.HumanoidRootPart.Position
RootPartHeartbeat = RunService.Heartbeat:Connect(function()
if character:FindFirstChild("HumanoidRootPart") then --If the player jumps into the void or their character doesn't exist for some reason, this will stop this block of code from running
local DistanceFromLastPosition = (character.HumanoidRootPart.Position-LastPosition).magnitude
Speed.Value = Speed.Value+(DistanceFromLastPosition*SpeedPerStud)
character.Humanoid.WalkSpeed = Speed.Value
LastPosition = character.HumanoidRootPart.Position
end
end)
end)
player.CharacterRemoving:Connect(function()
RootPartHeartbeat:Disconnect() --Prevents **serious** memory leaks AND errors!
end)
end
Players.PlayerAdded:Connect(playerAdded)
You’re all set! It should work. If it doesn’t, you can download the place file:
SpeedSim.rbxl (18.6 KB)
If you have any problems, please reply with them. On another note, if this did help you, please mark me as solution! You can do this by pressing the Solution on the bottom right of my post.
Thank you!!!
Urmm I don’t want to be spoon fed… I had a problem and was trying to solve it…
I don’t know a alot about scripting that is why I am trying to and then ask you guys for any help and any sugestions… If I wanted to be spoon fed I could just download a Speed Simulator of youtube
But thanks for the script I am going to try to edit it and do it in my own way…
Thanks I am busy with a youtube playlist Scripting for beginers so hope fully I learn some stuff of it.
Or maybe, you can detect if the player is moving or not with:
(little hacky way I use)
Set distance is that way because, when a Roblox player moves, their legs move up .1 or .2 studs from the opposite leg. That’s why I called this the “Hacky way” of doing things.
local UIS = game:GetService("UserInputService")
local setDist = 0.1 --can be any value
local function isMoving(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.W and if (player.Humanoid.RightLeg - player.Humanoid.LeftLeg).magnitude >= setDist then
while true do
player.Humanoid.WalkSpeed = player.Humanoid.WalkSpeed +1 --can be any value as well
local RunService = game:GetService("RunService").RenderStepped:Wait()
end
end
UIS.InputBegan:Connect(isMoving)
Wasn’t tested so i’m not sure if it runs or not
i know this was solved but there is an easier way to do this `
local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharachterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local walking = false
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Running then
walking = true
end
end)
while walking == true do
humanoid.WalkSpeed += 1
wait()
end`