How can I make a speed gamepass?

Hello, I want to make a speed gamepass, but my script doesn’t work.
This is the script, and it is located inside ServerScriptService.

local player = game.Players.LocalPlayer
local character = player.CharacterAdded()
local humanoid = character.Humanoid

game.Players.PlayerAdded:Connect(function(player)
	local success, boughtGamepass = pcall(function()
		return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237735)
	end)

	if success and boughtGamepass then
		humanoid.Walkspeed = 28
	end
end)

Is there any problem with the script? Thank you.

3 Likes

if this a server script, you can’t get the local player

mess with those inside the PlayerAdded event

1 Like
game.Players.PlayerAdded:Connect(function(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character.Humanoid
    local success, boughtGamepass = pcall(function()
        return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237735)
    end)

    if success and boughtGamepass then
        humanoid.Walkspeed = 28
    end
end)
1 Like

Try this buddy :slight_smile:

local Serv = game:GetService("GamePassService")

local MServ = game:GetService("MarketplaceService")

workspace.ChildAdded:Connect(function(char)
	local getpl = game:GetService("Players"):FindFirstChild(char.Name)
	if char:FindFirstChild("HumanoidRootPart") ~= nil then
		if MServ:UserOwnsGamePassAsync(getpl.UserId, 19237735) then
			char.Humanoid.WalkSpeed = 28
		end
	end
end)
4 Likes

The problem in your script is it probably stops working in first 3 lines, first off all LocalPlayer doesn’t exists on server so it will return nil and there’s no way to do player.CharacterAdded() you can do player.CharacterAdded:Wait() instead but let’s remove first 3 lines and do everything inside PlayerAdded and CharacterAdded events…

local function CheckGamepass(player)
    local success, boughtGamepass = pcall(function()
		return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237735)
	end)

	if success and boughtGamepass then
        if player.Character and player.Character:FindFirstChild("Humanoid") then
            player.Character.Humanoid.Walkspeed = 28
        else
            player.CharacterAdded:Wait()
            player.Character:WaitForChild("Humanoid")
            player.Character.Humanoid.Walkspeed = 28
        end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	CheckGamepass(player)

    player.CharacterAdded:Connect(function(character)
        CheckGamepass(game.Players:GetPlayerFromCharacter(character))
    end)
end)

If you don’t use CharacterAdded event it will not work after you respawn so it’s better to use CharacterAdded too. Let me know if it helps :slightly_smiling_face:

2 Likes

why is ChildAdded used for this case instead of PlayerAdded

and why are you checking for the Head and not the HumanoidRootPart?

1 Like

I made this in R6 my bad change it to HumanoidRootPart, and for the ChildAdded it’s for check when a player respawn, for me it was a better way

bro for that you just use CharacterAdded

local MPS = game:GetService(“MarketplaceService”)

game.Players.PlayerAdded:Connect(function(player)
local ownGamepass = MPS:UserOwnsGamePassAsync(player.UserId, 19237735)

player.CharacterAdded:Connect(function(char)
	if ownGamepass then
		char.Humanoid.Walkspeed = 28
	end
end)

end)

1 Like

Is this part for players without the gamepass?

No, it is for waiting for Character or Humanoid to be added if they return nil so it won’t cause errors

1 Like

@D0RYU, @iiNeZoXii, @AtomTostcuOzgurUsta, @ancadejo10, do you know how to check the player speed in a game?

“Humanoid.WalkSpeed” you have that value right there

if you know how to use if statements it should be easy

1 Like

Walkspeed is the speed of a character. If walkspeed of an humanoid is too low the speed will be low.

This says that Walkspeed is not a vaild member of Humanoid “Ojnim0702.Humanoid”

You want to make an anti cheat/ anti walkspeed?

Use “WalkSpeed” instead of “Walkspeed”.

2 Likes

You said game.Players.LocalPlayer on the top. I’m pretty sure you can only say this in a local script since the local script is from the local player. This should also give an error with the humanoid because game.Players.LocalPlayer does not work with server scripts.

It says that Walkspeed is not a valid member of Humanoid “Workspace.Ojnim0702.Humanoid”

No, I want to make a gamepass that allows player to walk at the given speed.