Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
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

1
There are so many errors in this, you need to review some other scripts before you do this. raid6n 2196 — 4y
1
sorry ProbablyRiley 0 — 4y
0
Not down voting but please do some research before asking a question next time Trading_Opportunity 191 — 4y
0
Functions have to run before all if statements. Switch line 3 to line 2 and line 2 to line 3. TheRealPotatoChips 793 — 4y

2 answers

Log in to vote
3
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
1
ok ill check ProbablyRiley 0 — 4y
1
doesnt work i fixed 7 to end) and yeah ProbablyRiley 0 — 4y
1
lemme test something tho ProbablyRiley 0 — 4y
1
nvm it works now i just needed to change the walkspeed to 200 bc 20 is a little slow ProbablyRiley 0 — 4y
View all comments (3 more)
0
alr raid6n 2196 — 4y
1
pls look at my response thx royaltoe 5144 — 4y
0
ok ProbablyRiley 0 — 4y

Answer this question