✓ 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)
4 comments
There are so many errors in this, you need to review some other scripts before you do this.
sorry
Not down voting but please do some research before asking a question next time
Functions have to run before all if statements. Switch line 3 to line 2 and line 2 to line 3.