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

How can I make my Gamepass script perform this?

Asked by 9 years ago

So I have a script that Goulestem helped me edit and it adds speed when you join my game if you have a certain Gamepass. It works but it constantly adds the amount I want it to, it doesnt just add it once it keeps going. Like if I want it to add one it will add 1 the whole time you are alive. I only want it to add once everytime you join for the whole game not always adding more. my script:

local gps = game:GetService("GamePassService");
local id = script:WaitForChild("GamePassID");
local Speed = script:WaitForChild("WalkSpeedAmount");

game.Players.PlayerAdded:connect(function(Player)
    Player:WaitForDataReady()
    if gps:PlayerHasPass(Player , id.Value) then
        coroutine.resume(coroutine.create(function()
            while wait() do
                repeat wait() until Player.Character~=nil 
                local hum = Player.Character.Humanoid
                hum.WalkSpeed = hum.WalkSpeed + Speed.Value
            end
        end))
    end
end)

Inside this script is a GamePassID value which represents the ID, and the WalkSpeed which represent the amount of speed I want to add. Please help me if you can. THANKS!

1 answer

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

The problem here is that you're constantly adding the WalkSpeed in a Loop. Take the code out of the loop and you're good(:

Also, I don't know why you have a coroutine there(;

local gps = game:GetService("GamePassService");
local id = script:WaitForChild("GamePassID");
local Speed = script:WaitForChild("WalkSpeedAmount");

game.Players.PlayerAdded:connect(function(Player)
    Player:WaitForDataReady()
    if gps:PlayerHasPass(Player , id.Value) then
        repeat wait() until Player.Character~=nil 
        local hum = Player.Character.Humanoid
        hum.WalkSpeed = hum.WalkSpeed + Speed.Value
    end
end)

-EDIT-

To make your character always have the walkspeed enhancement, you need to add the speed in a CharacterAdded Event. So that whenever the player respawns, it will check if they have the pass and then if they do, give them the enhanced speed. Checking with a CharacterAdded event also prevents users of your game having to rejoin to activate the GamePass(:

local gps = game:GetService("GamePassService");
local id = script:WaitForChild("GamePassID");
local Speed = script:WaitForChild("WalkSpeedAmount");

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(char) --CharacterAdded event
        char:WaitForChild("Humanoid") --Just to be safe(;
        if gps:PlayerHasPass(Player , id.Value) then
            local hum = Player.Character.Humanoid
            hum.WalkSpeed = hum.WalkSpeed + Speed.Value
        end
    end)
end)
0
One more problem, when I die it goes away I want them to have it the whole game, how can I do that? TixyScripter 115 — 9y
0
To keep the speed, even when you respawn, you're going to have to add the speed in a CharacterAdded event. I'll edit one in right now(; Goulstem 8144 — 9y
Ad

Answer this question