Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Speed Gamepass Resets When Player Dies?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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!

0
I'm using a serverscript? How would I get .LocalPlayer Jomeliter 55 — 4y
0
you can't use .LocalPlayer inside of a normal script, there are other ways to do it instead jediplocoon 877 — 4y
Ad
Log in to vote
0
Answered by
0msh 333 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
Doesn't work Jomeliter 55 — 4y
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 0msh 333 — 4y
0
? JesseSong 3916 — 4y
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

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

Answer this question