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

How can I change this Walkspeed gamepass script for it to work?

game.Players.PlayerAdded:Connect(function(plr)
 if game:GetMarketService("MarketplaceService"):UserOwnsPassAsync(plr.Id, 1623743476843467525764762345273567473564576235673) then
  plr.CharacterAdded:Connect(function()
   wait()
  char:FindFirstChild("Humanoid").WalkSpeed = 20 
  end
 end
end)

please help

4 comments

1

There are so many errors in this, you need to review some other scripts before you do this.

1

sorry

0

Not down voting but please do some research before asking a question next time

0

Functions have to run before all if statements. Switch line 3 to line 2 and line 2 to line 3.

2 answers

✓ Accepted answer

Use UserOwnsGamePassAsync to check if the player has a pass:

local gamepassId= YOUR GAMEPASS's ID

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		local hasGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassId) 
		if hasGamepass then
   			plr.Character:FindFirstChild("Humanoid").WalkSpeed = 200
		end
	end)
end)

#Preventing speed hackers: Keep in mind that hackers can change their characters physics which means they can change their speed. You should have some sort of check to see if they DON'T own the gamepass and they're faster than normal.

The script would look something like this:

local gamepassId = YOUR GAMEPASS's ID

local previousPositions = {}
local MAX_SPEED = 25  

function checkMovement(player)
	local character = player.Character
		
	if character then
		local hasGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassId) 
		local previousPosition = previousPositions[player.Name]

		if not hasGamepass and previousPosition then
			local distanceTraveled = (Vector3.new(previousPosition.X,0,previousPosition.Z) - Vector3.new(character.HumanoidRootPart.Position.X,0,character.HumanoidRootPart.Position.Z)).magnitude
			print(distanceTraveled)
			if distanceTraveled > MAX_SPEED then
				player.Character.HumanoidRootPart.Position = previousPositions[player.Name]
			end
		end

		previousPositions[player.Name] = player.Character.HumanoidRootPart.Position
	end
end

while wait(1) do
	for _, player in pairs(game.Players:GetPlayers()) do
		checkMovement(player)
	end
end 


--remove player from previousPositions table when they leave the game
game.PlayerRemoving:Connect(function(player)
	previousPositions[player.Name] = nil
end)

Previous Script:


game.Players.PlayerAdded:Connect(function(plr)
 if game:GetMarketService("MarketplaceService"):UserOwnsPassAsync(plr.Id, 1743777) then -- what is getmarketservice? Use GetService. Also, its UserOwnsGamePassAsync and plr .Id should be plr.UserId
  plr.CharacterAdded:Connect(function()
   wait()
  char:FindFirstChild("Humanoid").WalkSpeed = 20 
  end
 end
end)

Updated script:

local id = id
game.Players.PlayerAdded:Connect(function(plr)
 if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, id) then 
  plr.CharacterAdded:Connect(function()
   wait()
   plr.Character:FindFirstChild("Humanoid").WalkSpeed = 20 -- Change this to what walkspeed you want, default is 16.
  end)
 end
end)

7 comments

1

ok ill check

1

doesnt work i fixed 7 to end) and yeah

1

lemme test something tho

1

nvm it works now i just needed to change the walkspeed to 200 bc 20 is a little slow

0

alr

1

pls look at my response thx

0

ok

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