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

What's wrong with this walkspeed gamepass script?

Asked by 10 years ago
local MegaVipGamepassId = 0 -- Gamepass Id

game.Players.PlayerAdded:connect(function(Player)
    Player:WaitForDataReady()
    if game:GetService("GamePassService"):PlayerHasPass(Player, MegaVipGamepassId) then
        coroutine.resume(coroutine.create(function()
            while wait() do
                repeat wait() until Player.Character ~= nil 
                Player.Character.Humanoid.WalkSpeed = 32
            end
        end))
    end
end)

I'm getting this error:

Humanoid is not a valid member of Model Script 'ServerScriptService.Script', Line 9 Stack End

0
try Player.Character:WaitForChild("Humanoid").WalkSpeed = 32. NinjoOnline 1146 — 10y
0
^The WaitForChild method doesn't return the child you're waiting for, it returns the time it took for the child to not be nil. So by you saying that it's like saying wait(1).WlkSpeed = 32 Goulstem 8144 — 10y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

I suggest you don't use loops, they're very inefficient

An alternative to using loops would be just checking everytime their character adds - with a CharacterAdded event. This will also eliminate the problem of having to rejoin when you buy the pass.

local passId = 0 -- Gamepass Id
local speed = 32 --The speed to add

game.Players.PlayerAdded:connect(function(Player)
    plr.CharacterAdded:connect(function(char)
        if game:GetService("GamePassService"):PlayerHasPass(Player, passId) then
            repeat wait() until char:FindFirstChild('Humanoid') ~= nil
            char.Humanoid.WalkSpeed = speed
        end
    end)
end)
Ad

Answer this question