So I made a gamepass that grants you more walkspeed than usual in my game, the only problem I’m having is that when someone dies, the walkspeed returns to it’s normal state; even though I have tried several solutions that comes out of my head, it still does not work. Can someone please tell me what I have done wrong with this script? Thank you for reading.
Use pcalls along with UserOwnsGamePassAsync - to prevent issues when the web is down.
Maybe this would help:
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerService = game:GetService("Players")
local GamepassID = 68425756 -- your gamepass
local NewWalkSpeed = 24 -- how much speed you want them to have
local function CheckIfOwnsPass(Player)
Player.CharacterAppearanceLoaded:Connect(function(Char)
local success,result = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamepassID)
end)
if success then
if result then
local Humanoid = Char.Humanoid or Char:WaitForChild("Humanoid")
Humanoid.WalkSpeed = NewWalkSpeed
else
warn(result)
end
end
end)
end
PlayerService.PlayerAdded:Connect(CheckIfOwnsPass)
This does seem to work when somebody joins the game, but it does not work once somebody dies in the game, are they any more lines of code I have to put?
use CharacterAdded Event to check whenever the character gets added.
or if this is a localscript, put it in StarterCharacterScripts and remove the Died Event.
here make a new script in ServerScriptService and try this.
local SpeedId = 72170033
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local success,result = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,SpeedId)
end)
if not success then return end
if result then
local Humanoid = char:WaitForChild("Humanoid")
Humanoid.WalkSpeed = 24
end
end)
end)