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

Need to add health and speed instead of setting it?

Here it is set to '=' I want it to be set to '+' instead so that the gamepasses can stack if they buy more than one. How do I do this?

local WalkSpeedID = 361576482
local HealthBoostID = 361576482
local Cash1ID = 361576482

local WalkSpeedAmount = 10
local HealthBoostAmount = 20
local Cash1Amount = 5000

local MarketPlace = game:GetService("MarketplaceService")
game.Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character)
		if MarketPlace:PlayerOwnsAsset(Player, WalkSpeedID) then
			Character:WaitForChild("Humanoid").WalkSpeed = WalkSpeedAmount
		end
		if MarketPlace:PlayerOwnsAsset(Player, HealthBoostID) then
			Character:WaitForChild("Humanoid").MaxHealth = HealthBoostAmount
		end
	end)
	local Money = game.ServerStorage.PlayerMoney:WaitForChild(Player.Name)
	if MarketPlace:PlayerOwnsAsset(Player, Cash1ID) then
		Money.Value = Money.Value + Cash1Amount
	end
end)

2 answers

#They way we can do it is simple


Take its current value, and add to it. Do this by doing the following:

x = 1

x = x + 1

print(x)

Output:

2


Let's put this into your code on line 13


Character:WaitForChild("Humanoid").WalkSpeed = Character.Humanoid.Walkspeed + WalkSpeedAmount

Before I go on, I urge you to check out some scripting tutorials. Things such as this should be learned before you attempt to do advanced stuff. Also, I'd recommend comprehending your scripts; I assume you copied this from somewhere, as what you're asking for is done on line 21 already.

But I digress. You would add the health/speed to the boost.

local WalkSpeedID = 361576482
local HealthBoostID = 361576482
local Cash1ID = 361576482

local WalkSpeedAmount = 10
local HealthBoostAmount = 20
local Cash1Amount = 5000

local MarketPlace = game:GetService("MarketplaceService")
game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        if MarketPlace:PlayerOwnsAsset(Player, WalkSpeedID) then
            Character:WaitForChild("Humanoid").WalkSpeed = Character:WaitForChild("Humanoid").WalkSpeed + WalkSpeedAmount
        end
        if MarketPlace:PlayerOwnsAsset(Player, HealthBoostID) then
            Character:WaitForChild("Humanoid").MaxHealth = Character:WaitForChild("Humanoid").MaxHealth + HealthBoostAmount
        end
    end)
    local Money = game.ServerStorage.PlayerMoney:WaitForChild(Player.Name)
    if MarketPlace:PlayerOwnsAsset(Player, Cash1ID) then
        Money.Value = Money.Value + Cash1Amount
    end
end)

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