Module script value manipulation

This is a module script located in replicated storage and is used to determine drop chances of cases

If the user owns a specific gamepass i want these values to be changed but it’s not working, any ideas??

local properties = {}
local gamepassId = 735558039
local ms = game:GetService("MarketplaceService")
print("Module script running")

local commonChance = 50
local uncommonChance = 25
local rareChance = 15
local epicChance = 8
local legendaryChance = 3

-- Function to check if a player owns the gamepass
local function playerOwnsGamepass(player)
	if player and player.UserId then
		local success, hasPass = pcall(function()
			return ms:UserOwnsGamePassAsync(player.UserId, gamepassId)
		end)
		return success and hasPass
	end
	print("Module script gamepass unowned")
	return false
end

game.Players.PlayerAdded:Connect(function(player)
	-- Check if the player owns the gamepass
	if playerOwnsGamepass(player) then
		commonChance = 40
		uncommonChance = 20
		rareChance = 25
		epicChance = 15
		legendaryChance = 7.5
	else
		print("User does not own specific gamepass and their chance won't be increased.")
	end
end)

-- Default properties
properties["Items"] = {
	"Burning Sensation", "Blue Ripples", "Endless Void", "Angel of Angels", "Pink Cyborg", "Orange Dash",
}

properties["Chances"] = {
	Common = commonChance,
	Uncommon = uncommonChance,
	Rare = rareChance,
	Epic = epicChance,
	Legendary = legendaryChance,
}

properties["Price"] = 1000
properties["Image"] = "rbxassetid://16612003467"

return properties

4 Likes

Instead of ‘return success and haspass’ do:
‘If success then
return haspass
else
return false
end’

2 Likes

Or instead of ‘return false’ you could do:
‘playerOwnsGamepass(player)’ so it retries.

Um… “module script located in replicated storage”

This can be hacked. You need to store it somewhere that cannot be accessed by everyone.

Like, ServerScriptService.

2 Likes

The server scripts dont notice changes made by local scripts and local script cant access the module if it somewhere like serverstorage.

So i think there nothing wrongs in having module script in replicatedStorage.

ModuleScripts and LocalScripts can both be hacked,

1 Like

true that’s why there no point in hiding the module script. Cause if the local script has to access it then the module has to be somewhere on client side.

My point was they are checking for a GamePass and changing values based on that info.

So using a ModuleScript that can be accessed by the Client is not the way to go.

Since it didn’t work for me, I’ve decided to do another approach.

Server Side Script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local marketplaceService = game:GetService("MarketplaceService")
local drpChecker = replicatedStorage:WaitForChild("DropRateChecker")
local gamepassId = 735558039

local function calculateChances(player)
	local commonChance, uncommonChance, rareChance, epicChance, legendaryChance

	local owned = marketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId)

	if owned then
		commonChance = 40
		uncommonChance = 20
		rareChance = 25
		epicChance = 15
		legendaryChance = 7.5
	else
		commonChance = 50
		uncommonChance = 25
		rareChance = 15
		epicChance = 8
		legendaryChance = 3
	end

	drpChecker:FireClient(player, commonChance, uncommonChance, rareChance, epicChance, legendaryChance)
end

game.Players.PlayerAdded:Connect(function(player)
	calculateChances(player)
end)

for _, player in ipairs(game.Players:GetPlayers()) do
	calculateChances(player)
end

Module Script

local properties = {}
local commonChance = nil
local uncommonChance = nil
local rareChance = nil
local epicChance = nil
local legendaryChance = nil
local loaded = false

local replicatedStorage = game:GetService("ReplicatedStorage")
local drpChecker = replicatedStorage:WaitForChild("DropRateChecker")

drpChecker.OnClientEvent:Connect(function(player, NewcommonChance, NewuncommonChance, NewrareChance, NewepicChance, NewlegendaryChance)
	NewcommonChance = commonChance
	NewuncommonChance = uncommonChance
	NewrareChance = rareChance
	NewepicChance = epicChance
	NewlegendaryChance = legendaryChance
	loaded = true
end)

properties["Items"] = {
	"Burning Sensation", "Blue Ripples", "Endless Void", "Angel of Angels", "Pink Cyborg", "Orange Dash",
}

repeat
	wait(1)
until loaded

properties["Chances"] = {
	Common = commonChance,
	Uncommon = uncommonChance,
	Rare = rareChance,
	Epic = epicChance,
	Legendary = legendaryChance,
}

properties["Price"] = 1000
properties["Image"] = "rbxassetid://16612003467"

return properties

Would this work?

“Would this work?”

Do you mean, “can this be hacked?”

Yes, if the Module is still located in ReplicatedStorage.

1 Like

No, I really don’t care about hacked. I just need the chances to change if user owns it

4 Likes

Why don’t you just test it?
Mikquint

I recently started working with moules, so correct me if im wrong. In my knowledge, when server requires a module it gets a copy of everything the module have. SO whatever the changes the client will make, will not replicate on server side. So if the gamepass and changing values are getting handled on the server side then idts there anything to worry about. And if its done on the client side then yea its easy to hack.

3 Likes

OnClientEvent can only be called from LocalScript, that’s the error I’m getting

If the ModuleScript is a server script, then I don’t understand why the gamepass checks doesn’t work on it

I’m not an expert on the details. I just know I have read a lot and everything I have read says they can be hacked. What “hacked” means, I don’t know for sure.

if you require this module from a server script then it will give you error cause OnClientEvent is used on client side.

Right, use OnServerEvent if inside a ServerScript.

…and server scripts are not able to send remote events to each other, so you can’t really do server script and server script for remotes

use bindable event for that to send event from server to server and client to client

Server To Server is a BindableEvent.