Hello I am having a minor problem. A little help will be appreciated. The problem is when I buy gamepass in game it works fine and give me speed. But when I die It no longer give me speed. Here is a video of gamepass and Image of my code.
MarketplaceService:UserOwnsGamePassAsync() caches (temporarily saves) the value from the first call to avoid redundancy. According to this post, the function will return false for 10 seconds before updating. I wouldn’t expect many players to die within 10 seconds of purchasing the game pass, so I’d probably write this off as a minor inconvenience.
Everything you need to do is create RemoteEvent and put it into ReplicatedStorage
Okay, next create local script and put it into StarterGui
write this into local script
local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("Humanoid").Died:Connect(function()
game.ReplicatedStorage.Death:FireServer()
end)
Next create script and put it into ServerScriptService
write this into script
local mps = game:GetService("MarketplaceService")
local gamepass_id = --gamepass id here
game.ReplicatedStorage.Death.OnServerEvent:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if mps:UserOwnsGamePassAsync(plr.UserId, gamepass_id) then
char:FindFirstChild("Humanoid").WalkSpeed = 300
end
end)
end)
This is going to generate unnecessary network traffic and has the capability to generate false or mishandled results especially since you have no security on that remote. This entire process can be done exclusively on the server. The client should not be involved at any step.
It’d be much better to cache the fact that the player owns the pass anyway. Make your own cache. The initial ownership state should be whatever UserOwnsGamePassAsync returns and then be modified from PromptGamePassPurchaseFinished. Ownership check can be done from here then, not MarketplaceService after every respawn.