Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How Do I Assign An IntValue to be the Player's WalkSpeed?

Asked by 1 year ago

I'm working on a project which has 6 different playable characters with 6 different walkspeeds. Selecting any of the characters will change the IntValue's value to the speed the character is going to be. How do I make a script, where the IntValue's value is the humanoid's walkspeed. The IntValue is stored in a frame inside a ScreenGUI. Thanks

4 answers

Log in to vote
1
Answered by
Komas19 34
1 year ago

First off, you will need a TextLabel, you can name it what even you want then place it in the Frame. Then place the IntValue inside then the Frame. Then create a LocalScript You can name it whatever you want, and put it inside the TextLabel.

Inside the LocalScript, you need to put this script :

local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local textlabelName = "TextLabel"
local intvalueName = "Value"

while wait() do
    local walkspeed = hum.WalkSpeed
    script.Parent.Parent[intvalueName].Value = walkspeed
    script.Parent.Text = script.Parent.Parent[intvalueName].Value
end

In local textlabelName = "TextLabel", rename "TextLabel" by the name of your TextLabel. In local intvalueName = "Value", rename "Value" by the name of your IntValue

This should work!

0
if it doesn't work i might get back on you tomorrow Komas19 34 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

So I figured it out. It's kind of like what Komas19 was suggesting with some changes

local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local WalkSpeed = hum.WalkSpeed

while wait() do
    hum.WalkSpeed = script.Parent.CharacterSelection.Background.SpeedValue.Value

end
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
1 year ago
Edited 1 year ago

Hello,

I see you're struggling, let me help you!

So you are trying to set the speed locally so no one will see you run that fast only you, So I cooked up a new script for you!

Insert a RemoteEvent in ReplicatedStorage called SetSpeed Insert a LocalScript in your TextLabel Insert a ServerScript/Script in ServerScriptService

(ReplicatedStorage is the best place to store your RemoteEvents, RemoteFunctions and Values)

If the scripts work, I'd appreciate if you Accept my answer otherwise tell me your error or problem

LocalScript Code:

local replicatedStorage = game:GetService("ReplicatedStorage")

local textLabel = script.Parent

while wait() do
    replicatedStorage:FindFirstChild("SetSpeed"):FireServer(textLabel.Text)
end

If you are using a Value

local replicatedStorage = game:GetService("ReplicatedStorage")

local speedValue = script.Parent:FindFirstChild("Speed")

while wait() do
    replicatedStorage:FindFirstChild("SetSpeed"):FireServer(speedValue.Value)
end

Script Code:

local replicatedStorage = game:GetService("ReplicatedStorage")

replicatedStorage:FindFirstChild("SetSpeed").OnServerEvent:Connect(function(player, speedAmount)
    if player then

        local char = player.Character

        if char then

            char:FindFirstChild("Humanoid").WalkSpeed = tonumber(speedAmount)

        end

    end
end)

If you are using a IntValue heres a second Script code:

local replicatedStorage = game:GetService("ReplicatedStorage")

replicatedStorage:FindFirstChild("SetSpeed").OnServerEvent:Connect(function(player, speedAmount)
    if player then

        local char = player.Character

        if char then

            char:FindFirstChild("Humanoid").WalkSpeed = speedAmount

        end

    end
end)
Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Answer this question