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

I am trying to change the walkspeed of a player but there is a problem and i dont know why?

Asked by 7 years ago

Here is the script:

Runner.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local p = game.Players:getPlayerFromCharacter(hit.Parent)
        if p.leaderstats.Class.Value == "Gunner"
            then p.leaderstats.Class.Value = "Runner"
            if p.leaderstats.Class.Value == "Runner" then
                p.Character:FindFirstChild("Humanoid").WalkSpeed.Value = 24
                if p.StarterGear.Tool ~= nil then
                    p.StarterGear.Tool:Destroy()
                end
            end
        end
    end
end)

The error is at line 9 and the outputs returns me: Workspace.Runner.Script:9: attempt to index field 'WalkSpeed' (a number value)

What is the error and how can I fix it?

0
Change StarterGear to Backpack Master_JJ 229 — 7y
0
THats not my problem right now.. I am trying to change the walkspeed that part works but the walkspeed does not y0ucef123 72 — 7y
0
When changing the WalkSpeed of a player you do not do .Value you just do game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24 yougottols1 420 — 7y
0
^ Note that I am not saying that is exactly how you are going to script it, I am just giving an example to as why you don't put the .Value yougottols1 420 — 7y
0
Ok thanks y0ucef123 72 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Well your problem is simple. You're trying to use WalkSpeed as though it was an IntValue, when in reality, WalkSpeed is actually a property of Humanoid.

Here's the fixed version of your code:

Runner.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local p = game.Players:getPlayerFromCharacter(hit.Parent)
        if p.leaderstats.Class.Value == "Gunner"
            then p.leaderstats.Class.Value = "Runner"
            if p.leaderstats.Class.Value == "Runner" then
                p.Character:FindFirstChild("Humanoid").WalkSpeed = 24
                if p.StarterGear.Tool ~= nil then
                    p.StarterGear.Tool:Destroy()
                end
            end
        end
    end
end)

Ad

Answer this question