Walk speed game pass script not working

I’m trying to make a script that will change the player’s walk speed if they buy the game pass.

I keep getting an error Userid is not a valid Player “Players.ej1334”
Stack Begin
Script ‘ServerScriptService.Walkspeed’, Line 8
Stack End

ServerScriptService:

local Players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")

Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Char)
		
		local Humanoid = Char:FindFirstChild("Humanoid")
		if MPS:UserOwnsGamePassAsync(Plr.Userid, 26372437) then
			Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed * 2
		end
	end)
end)

Like most programming languages, Lua is case-sensitive.

The property should written as UserId, not Userid.

you spelled userid wrong

try this

capitalization is important because lua is case sensitive

local Players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")

Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Char)
		
		local Humanoid = Char:FindFirstChild("Humanoid")
		if MPS:UserOwnsGamePassAsync(Plr.UserId, 26372437) then
			Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed * 2
		end
	end)
end)

Thank you very much I didn’t notice.

Small nitpick, but there is the possibility of the Humanoid not being able to be detected quickly in time which may result back as an error (Or nil from the Humanoid variable)

local Humanoid = Char:WaitForChild("Humanoid")

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.