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

How can I make these 2 scripts compatible?

So I have this script here to add speed when they join if they have a certain gamepass and it works completely:

gps = game:GetService("GamePassService");

id = script:WaitForChild("GamePassID");
Speed = script:WaitForChild("WalkSpeedAmount");

game.Players.PlayerAdded:connect(function(Player)
Player:WaitForDataReady()
if gps:PlayerHasPass(Player , id.Value) then
coroutine.resume(coroutine.create(function()
while wait() do
repeat wait() until Player.Character~=nil 
Player.Character:WaitForChild("Humanoid").WalkSpeed=Speed.Value
end
end))
end
end) 

There is a GamePassID inside of the script and also the SpeedAmount. That all works fine and dandy but then when I use my Dev product scripts there is a problem. My Dev script gives speed, health, etc. when you buy that certain Dev product. It does at speed and everything its just when you have a gamepass that adds speed it does not add anything for some reason. It may be a MarketPlace error? Dev Script:

local MarketplaceService = game:GetService("MarketplaceService")
local AddHealthID = 22137556 --ENTER 
local AddSpeedID = 22137544  --PASS
local AddGearID = 22137570   --IDS
local AddGear2ID = 22137564   --IDS
local AddGear3ID = 22137575  --HERE
local AddGear4ID = 22137566   --IDS
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MarketplaceService.ProcessReceipt = function(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    for i, player in ipairs(game.Players:GetPlayers()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == AddHealthID then
				player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 50 --Adds 50 to their current health
				player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
			end
			if receiptInfo.ProductId == AddSpeedID then
				player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 15 -- Adds 5 to their current Walkspeed
			end
			if receiptInfo.ProductId == AddGearID then
				game.ReplicatedStorage.GravityCoil:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
				-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you want them to get this item till they leave the game, Like renting it
			end
			if receiptInfo.ProductId == AddGear2ID then
				game.ReplicatedStorage.LockonLauncher:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
				-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you want them to get this item till they leave the game, Like renting it
			end
			if receiptInfo.ProductId == AddGear3ID then
				game.ReplicatedStorage.JetPack:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
				-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you want them to get this item till they leave the game, Like renting it
			end
			if receiptInfo.ProductId == AddGear4ID then
				game.ReplicatedStorage.EpicLaser:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
				-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you
			end
		end
	end
    PurchaseHistory:SetAsync(playerProductKey, true)	
    return Enum.ProductPurchaseDecision.PurchaseGranted	
end

If you could help me and make these two script compatible it would be really nice of you, THANKS!

1 answer

So your problem is that if you've bought the Developer Product, the GamePass functions don't work?

This might be due to the fact that you're Setting the WalkSpeed value, rather than actually adding it.

So standard WalkSpeed is 16? Your Dev Product adds 15, from that moment it's 31. So since you're SETTING the WalkSpeed in the gamepass functions..

Speed = script:WaitForChild("WalkSpeedAmount");

Player.Character:WaitForChild("Humanoid").WalkSpeed = Speed.Value

If Speed's value is 31(or 30, since that makes more sense), then you won't see any change.

So to fix this? Add the WalkSpeed rather than Setting it.

local gps = game:GetService("GamePassService");
local id = script:WaitForChild("GamePassID");
local Speed = script:WaitForChild("WalkSpeedAmount");

game.Players.PlayerAdded:connect(function(Player)
	Player:WaitForDataReady()
	if gps:PlayerHasPass(Player , id.Value) then
		coroutine.resume(coroutine.create(function()
			while wait() do
				repeat wait() until Player.Character~=nil 
				local hum = Player.Character.Humanoid
				hum.WalkSpeed = hum.WalkSpeed + Speed.Value
			end
		end))
	end
end)

2 comments

0

This works but it makes my go way to fast even when I changed the Walkspeedamount.

0

I see the problem it constantly adds it instead of adding the speed only once! But i dont know how to fix...

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