Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

5 comments

0

Change StarterGear to Backpack

0

THats not my problem right now.. I am trying to change the walkspeed that part works but the walkspeed does not

0

When changing the WalkSpeed of a player you do not do .Value you just do game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24

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

0

Ok thanks

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.