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

Gamepass Abilities Stop Whenever Player Dies??

Asked by 4 years ago

Once the player joins the game they have the X2 speed ability but once they die they lose it? I can't find a fix to this!? Any ideas why

Script in serverscriptservice

local MPS = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local SpeedX2_ID = 8291824

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


game.Players.PlayerAdded:Connect(function(plr)
    if MPS:UserOwnsGamePassAsync(plr.UserId,SpeedX2_ID) then
            game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed * 2
    end
end)

3 answers

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

as racoon said but made it easier

the plr value will update each time someone joins so that way is not reliable instead do this make a local script in the players backpack or startercharacter, really doesnt matter in the local script you do this


--also when finishing the promt purchase, fire that to the server, let the server handle that sort of stuff MPS.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased) if purchased and SpeedX2_ID == ido then plr.Character.Humanoid.WalkSpeed.Value = plr.Character.Humanoid.WalkSpeed.Value * 2 end end) local player = game:GetService("Players").LocalPlayer player.CharacterAdded:Connect(function() --you also need a remove event for this to work game:GetService("ReplicatedStorage"):WaitForChild("Remove event name here"):FireServer("Speed")--speed is just a variable you wanna fire to the server, can be literally anything as long as the server looks for that variable end)

make a server script in serverscriptservice and add this into that script

local MPS = game:GetService("MarketplaceService")
local SpeedX2_ID = 8291824
game:GetService("ReplicatedStorage"):WaitForChild("remote event name here").OnServerEvent:Connect(function(player,word)
    if word == "Speed" and MPS:UserOwnsGamePassAsync(plr.UserId,SpeedX2_ID) then--this is where you use the variable from the local script
local humanoid = plr.Character:WaitForChild("Humanoid")
humanoid.Speed = humanoid.Speed * 2
end)
Ad
Log in to vote
0
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years ago
Edited 4 years ago

Speed resets whenever a player dies. You'd need to have a CharacterAdded function. Example:

function Respawned(player)
    local plr = game.Players:FindFirstChild(player.Name)
        if MPS:UserOwnsGamePassAsync(plr.UserId,SpeedX2_ID) then
            game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed * 2
    end
end
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago
Edited 4 years ago
local MPS = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local SpeedX2_ID = 8291824

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


game.Players.PlayerAdded:Connect(function(plr)
    if MPS:UserOwnsGamePassAsync(plr.UserId,SpeedX2_ID) 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,SpeedX2_ID) then
            game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed * 2
    end
    end
end)

The only change I made is when the player dies, it checks again and gives them their speed

0
wont work since plr will update as soon as someone new joins making this unreliable if i remember lua correctly, been doing javascript lately and thats how it works there at least Gameplayer365247v2 1055 — 4y
0
This means for EVERY player joined this code will run for THEM. So every time that SPECIFIC player dies, it should give them their speed. haba_nero 386 — 4y

Answer this question