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

How Would I Use Module Scripts With Tables?

I have multiple scripts that require suffixes, and I always have to edit each and every single one of them so I decided to use module scripts. The problem is I never used them? Also do module scripts require functions?

Module Script

local module = {}
function module:getSuf(suf)
local suffixes = {
	'k','M','B','T','qd','Qn','sx','Sp','O',
	'N','de','Ud','DD','tdD','qdD','QnD','sxD',
	'SpD','OcD','NvD','Vgn'
}
module:getSuf(suffixes)
end
return module

Script

local rs = game:WaitForChild("ReplicatedStorage")
local events = rs:WaitForChild("Events")

game.Players.PlayerAdded:connect(function(plr)
	local module = require(game.ReplicatedStorage.Suffixes)
	module.getSuf(suf)

	local leaderstats = plr:WaitForChild("leaderstats")
	local stats = plr:WaitForChild("stats")
	
	local robux = stats.Robux
	local tix = stats.Tix
	
	local robuxstring = leaderstats.Robux
	local tixstring = leaderstats.Tix	
	
	robux.Changed:connect(function()
	
	for i = #suffixes,1, -1 do
		if robux.Value >= 10 ^ (i * 3) then
			robuxstring.Value = math.floor(robux.Value / 10 ^ ((i*3) - 2)) * 0.01 .. suffixes[i] .. "+"
			break
		elseif robux.Value <= 10 ^ 3 then
			robuxstring.Value = math.floor(robux.Value * 100) * 0.01
			break
		end
	end
end)
	
	tix.Changed:connect(function()
	
	for i = #suffixes,1, -1 do
		if tix.Value >= 10 ^ (i * 3) then
			tixstring.Value = math.floor(tix.Value / 10 ^ ((i*3) - 2)) * 0.01 .. suffixes[i] .. "+"
			break
		elseif tix.Value <= 10 ^ 3 then
			tixstring.Value = math.floor(tix.Value * 100) * 0.01
			break
		end
	end
end)
	
end)

Also my studio crashes.

2 comments

0

Er, can you reword your question? It's currently hard to understand what you're asking.

0

I have lots of scripts like the script below which requires the table in the module script.

1 answer

✓ Accepted answer

You can just instantly return the suffixes table value upon requireing like so:

return {
    'k','M','B','T','qd','Qn','sx','Sp','O',
    'N','de','Ud','DD','tdD','qdD','QnD','sxD',
    'SpD','OcD','NvD','Vgn'
}

This means when the module is required, it'll just return that array. To use this in your script, you can just do it like so:

local rs = game:WaitForChild("ReplicatedStorage")
local events = rs:WaitForChild("Events")

game.Players.PlayerAdded:connect(function(plr)
    local suffixes = require(game.ReplicatedStorage.Suffixes)

    local leaderstats = plr:WaitForChild("leaderstats")
    local stats = plr:WaitForChild("stats")

    local robux = stats.Robux
    local tix = stats.Tix

    local robuxstring = leaderstats.Robux
    local tixstring = leaderstats.Tix   

    robux.Changed:connect(function()

    for i = #suffixes,1, -1 do
        if robux.Value >= 10 ^ (i * 3) then
            robuxstring.Value = math.floor(robux.Value / 10 ^ ((i*3) - 2)) * 0.01 .. suffixes[i] .. "+"
            break
        elseif robux.Value <= 10 ^ 3 then
            robuxstring.Value = math.floor(robux.Value * 100) * 0.01
            break
        end
    end
end)

    tix.Changed:connect(function()

    for i = #suffixes,1, -1 do
        if tix.Value >= 10 ^ (i * 3) then
            tixstring.Value = math.floor(tix.Value / 10 ^ ((i*3) - 2)) * 0.01 .. suffixes[i] .. "+"
            break
        elseif tix.Value <= 10 ^ 3 then
            tixstring.Value = math.floor(tix.Value * 100) * 0.01
            break
        end
    end
end)

end)

Hopefully this solves your problem, if it does, please accept it as the answer, if not let me know by commenting below!

1 comment

0

Thanks Ill accept this answer although i solved after a couple minutes.

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