Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Speed Gamepass Resets When Player Dies?

Speed Gamepass resets whenever the player dies even though I made sure to make it active again once they die?!

ServerScript

local MPS = game:GetService("MarketplaceService")

MPS.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and 8946555 == ido then
        plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed * 2
    end
end)


game.Players.PlayerAdded:Connect(function(plr)
    if MPS:UserOwnsGamePassAsync(plr.UserId,8946555) then
            game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed * 2
    end
    plr.Character:FindFirstChild("Humanoid").Died:Connect(function()
wait(6)
        if MPS:UserOwnsGamePassAsync(plr.UserId,8946555) then
            game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed * 2
    end
end)
	end)
	
game.ReplicatedStorage.Speed.OnServerEvent:Connect(function(plr)
	
	plr.Character:WaitForChild("Humanoid").WalkSpeed = plr.Character:WaitForChild("Humanoid").WalkSpeed * 2 
	
end)

PrompPurchase

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local GamepassID = 8946601  -- Change this to your developer product ID
 
-- Function to prompt purchase of the developer product
script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer, GamepassID)
end)

MarketplaceService.PromptGamePassPurchaseFinished:connect(function(player, id, purchased)
	if id == GamepassID and purchased then
		game.ReplicatedStorage.VIP:FireServer()
	end
end)

3 answers

It's actually very simple :D

I once struggled with this too, i know it's a pain in the ass not getting things done.

We simply use a function called .CharacterAdded

Every-time the player loads in, this function will be called. Useful in calculating the players deaths

Here's a short example:

game.Players.LocalPlayer.CharacterAdded:Connect(function()
   print("The player just died, or loaded in")
end)

I won't tell you the script, but it's got to do something with this. Why you may ask?

You learn by researching, and improvising.

This is how i learned LUA.

Enjoy your scripting career!

2 comments

0

I'm using a serverscript? How would I get .LocalPlayer

0

you can't use .LocalPlayer inside of a normal script, there are other ways to do it instead

just add a CharacterAdded to check when the player's character is added and change the walkspeed

new server script:

local MPS = game:GetService("MarketplaceService")

MPS.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and 8946555 == ido then
        plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed * 2
    end
end)


game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
    if MPS:UserOwnsGamePassAsync(plr.UserId,8946555 ) then
            char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed * 2
    end
end)
    end)

game.ReplicatedStorage.Speed.OnServerEvent:Connect(function(plr)

    plr.Character:WaitForChild("Humanoid").WalkSpeed = plr.Character:WaitForChild("Humanoid").WalkSpeed * 2 

end)

3 comments

0

Doesn't work

0

mb, forgot to change the way of finding the player's character way to char. should work now. and the speed remote isn't a good idea

0

?

I would suggest using a while loop to check whether the player has died then promptgamepasspurchase on line 14 And I'm on mobile so I can't test it

Script


~~~local MPS = game:GetService("MarketplaceService")

MPS.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and 8946555 == ido then
        plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed * 2
    end
end)


game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
    if MPS:UserOwnsGamePassAsync(plr.UserId,8946555 ) then
            char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed * 2
    end
end)
    end)

game.ReplicatedStorage.Speed.OnServerEvent:Connect(function(plr)

    plr.Character:WaitForChild("Humanoid").WalkSpeed = plr.Character:WaitForChild("Humanoid").WalkSpeed * 2 

end)~~~~~~~~~~~~~

This discussion is preserved as it was. New answers, comments, and votes are closed.