For some reason, this doesnt last after they die? Wouldn't the player added just repeat the script? Im confused, any way to make it work even after they die/respawn?
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 836664 local function onPlayerAdded(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then print(player.Name .. " owns the game pass with ID " .. gamePassID) player.Character.Humanoid.WalkSpeed = 30 end end game:GetService('Players').PlayerAdded:Connect(onPlayerAdded)
You have to do it on CharacterAdded instead of PlayerAdded, as PlayerAdded only fires when the player joins. For example:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) --this will fire every time a player's character spawns character:WaitForChild("Humanoid") onPlayerAdded(player) end) end)
Also, userId is deprecated, it should be UserId instead, so that part is fine. You should also keep in mind that exploiters can change their walkspeed at will, so you might want to add some server-sided checks to try and prevent this (such as repeatedly checking how far each player travels from the server).
I've added the character added function, but i've still not got it to work?
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 836664 game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) --this will fire every time a player's character spawns character:WaitForChild("Humanoid") onPlayerAdded(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then print(player.Name .. " owns the game pass with ID " .. gamePassID) player.Character.Humanoid.WalkSpeed = 30 end end) end) game:GetService('Players').PlayerAdded:Connect(onPlayerAdded)