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!
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)