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

How do you make gamepasses multiply the amount of points given?

I am trying to use gamepasses to multiply the amount of points / "Steps" given to the player. How would I do this? I would like to make it so if the player has pass4, it does:

plr.leaderstats["Steps"].Value = plr.leaderstats["Steps"].Value + 4

If they have pass3, it does:

plr.leaderstats["Steps"].Value = plr.leaderstats["Steps"].Value + 3

And if they have pass2, it does

plr.leaderstats["Steps"].Value = plr.leaderstats["Steps"].Value + 2
--POINT ADDER--

local vec3 = Vector3
local pass4 = 1163402460
local pass3 = 1163401151
local pass2 = 1163394115

local function CheckForWalk(plr, hum)
    pcall(function()
        while wait() do
            if hum.MoveDirection ~= vec3.new(0, 0, 0) then --if the character is moving
                while wait(5/plr.leaderstats["Steps"].Value^(1/2)) do --while the player is moving, increase their step points each second.
                    if hum.MoveDirection ~= vec3.new(0, 0, 0) then
                        plr.leaderstats["Steps"].Value = plr.leaderstats["Steps"].Value + 1
                    else
                        break
                    end
                end
            end
        end
    end)
end

game.Players.PlayerAdded:connect(function(plr)--NOTE: this still breaks when "W" is held in and you die.
    plr.CharacterAdded:Connect(function(char)
        local hum = char:WaitForChild("Humanoid")
        CheckForWalk(plr, hum)
    end)
end)

Thank you for the help!

2 comments

0

To be honest, I think they teach multiplication before exponentiation.

0

I am trying to figure out how to include the gamepasses.

1 answer

✓ Accepted answer

To check if the player owns a certain pass, you can use the PlayerHasPass function. Now, instead of writing out the function call a bunch of times for each ID, you could implement a dictionary :)

Name your keys numerical values, corresponding to the desired multiplier. Have the values be the ID of pass needed to obtain said multiplier.

Then iterate through the array and check if the player owns the pass. If they do, pass the multiplier using string patterns.

local pService = game:GetService("GamePassService")
local vec3 = Vector3
local passes = { --Dictionary
	["Pass4"] = 1163402460,
	["Pass3"] = 1163401151,
	["Pass2"] = 1163394115
}

local function CheckForWalk(plr, hum, add) --Add parameter
	pcall(function()
		while wait() do
			if hum.MoveDirection ~= vec3.new(0, 0, 0) then
				while wait(5/plr.leaderstats["Steps"].Value^(1/2)) do
					if hum.MoveDirection ~= vec3.new(0, 0, 0) then
						--variable for readability
						local steps = plr.leaderstats.Steps
						steps.Value = steps.Value + add
					else
						break
					end
				end
			end
		end
	end)
end

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local add = 1;
		for i,v in next,passes do
			if pService:PlayerHasPass(plr, v) then
				--%d+ for numbers, tonumber to make it a number
				add = tonumber(i:match("%d+"))
				break
			end
		end
		CheckForWalk(plr, hum, add) --Pass multiplier to function
	end)
end)

######You should look into using a debounce

1 comment

0

Thank you. I haven’t used a denounce before, but I will look at how they are used when I get home. You have helped me a lot so far while I have been learning.

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