Updating Walkspeed in real time

So, I am working on a speed simulator-type game, where a player’s speed is determined based on a value,

How can I update the player’s speed in real-time as they click?
I am willing to provide any script or resource that you might need to help answer this question

What do you mean by in real time? What other option would there be?

Add to their Humanoid.WalkSpeed property, this will make them faster.

The default is 16

Once the value change, the speed changes aswell is what i meant, sorry for the confusion

Move this to #help-and-feedback:scripting-support

1 Like

oh ok then. Do you have a leaderboard script or a DataStore script in your game?

it is in #help-and-feedback:scripting-support

I have not yet implemented datastore, but I do have leaderstats, yes

I believe you can do both of these at the same time. In pseudocode, it would be like this:

mouse clicked
     change number value object or variable by some amount
     walkspeed += that number/variable * some ratio to compensate (you don't need this if you want the value to be one to one)

How would I implement that into my current “Click Script”?

local player = game.Players.LocalPlayer
local Speed = player:WaitForChild("leaderstats"):WaitForChild("Speed")
local sound = script["Pop Sound!"]
debounce = true


game:GetService("UserInputService").InputBegan:Connect(function(input, engine_processed)
if engine_processed then
		return
	end

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if debounce == true then
			debounce = false
			Speed.Value = Speed.Value +1
			sound:Play()
			wait(0.15)
			debounce = true
		end
	end
end)

ok so what you want to do is whenever the value changes add to the walkspeed this script would work I think but you would need to change the Values and stuff depending on how much they get per click

game.Players.PlayerAdded:Connect(function(player)

-- add in all your leaderstats
 [Value containing your Speed/Clicks].Changed:Connect(function()

  local Char = player.Character or player.CharacterAdded:Wait() -- I think that is how it works but unsure on the second bit
  if not Char then return end
  local Hum = Char.Humanoid
  if not Hum then return end
  Hum.WalkSpeed =  ([Value containing your Speed/Clicks].Value/[put i value here but it will be alot of trial and error to get the best result]) + 16


 end)
end)

I haven’t tested this btw so there may be bugs

After speed value = speed.value + 1, you would want to change the player speed as well with the Speed.Value

1 Like

you can do that with a propertychangedsignal when the value changes you set the walkspeed to the value value

I don’t think you truly need a separate value. Couldn’t you just use a script that changes Humanoid.Walkspeed?
I don’t even think a separate value is needed for data-saving.

Im not quite sure what you mean by that, could you perhaps give an example?

This worked for me, thank you a lot!

1 Like