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)
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)
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)