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 2 years 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
2 years 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 :

01local players = game:GetService("Players")
02local plr = players.LocalPlayer
03local char = plr.Character
04local hum = char:WaitForChild("Humanoid")
05local textlabelName = "TextLabel"
06local intvalueName = "Value"
07 
08while wait() do
09    local walkspeed = hum.WalkSpeed
10    script.Parent.Parent[intvalueName].Value = walkspeed
11    script.Parent.Text = script.Parent.Parent[intvalueName].Value
12end

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 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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

01local players = game:GetService("Players")
02local plr = players.LocalPlayer
03local char = plr.Character
04local hum = char:WaitForChild("Humanoid")
05local WalkSpeed = hum.WalkSpeed
06 
07while wait() do
08    hum.WalkSpeed = script.Parent.CharacterSelection.Background.SpeedValue.Value
09 
10end
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
2 years ago
Edited 2 years 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:

1local replicatedStorage = game:GetService("ReplicatedStorage")
2 
3local textLabel = script.Parent
4 
5while wait() do
6    replicatedStorage:FindFirstChild("SetSpeed"):FireServer(textLabel.Text)
7end

If you are using a Value

1local replicatedStorage = game:GetService("ReplicatedStorage")
2 
3local speedValue = script.Parent:FindFirstChild("Speed")
4 
5while wait() do
6    replicatedStorage:FindFirstChild("SetSpeed"):FireServer(speedValue.Value)
7end

Script Code:

local replicatedStorage = game:GetService("ReplicatedStorage")

01replicatedStorage:FindFirstChild("SetSpeed").OnServerEvent:Connect(function(player, speedAmount)
02    if player then
03 
04        local char = player.Character
05 
06        if char then
07 
08            char:FindFirstChild("Humanoid").WalkSpeed = tonumber(speedAmount)
09 
10        end
11 
12    end
13end)

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

01local replicatedStorage = game:GetService("ReplicatedStorage")
02 
03replicatedStorage:FindFirstChild("SetSpeed").OnServerEvent:Connect(function(player, speedAmount)
04    if player then
05 
06        local char = player.Character
07 
08        if char then
09 
10            char:FindFirstChild("Humanoid").WalkSpeed = speedAmount
11 
12        end
13 
14    end
15end)
Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

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

Answer this question