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

Need to add health and speed instead of setting it?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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
Ad
Log in to vote
-1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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)

Answer this question