I’m trying to make my module secure by putting it in ServerScriptService.
Well, the function I’m running never seems to work on both local and server script. I’ve tried a remote event, tried changing the function in the module script for local and/or server. I’ve even tried to swap the greater-than sign. Never worked.
It seems to be a problem with the module script, I’ve tried debugging it so mind the atrocious amount of print functions.
One main thing to note, I’ve tried this in a local script and the module was in replicated storage, still didn’t work at all and didn’t print anything. In the output for the server script it says this:
and prints nothing.
For local script it doesn’t print anything nor error.
Server script(first attempt):
local module = require(game:GetService("ServerScriptService"):WaitForChild("Buy"))
local test = workspace:WaitForChild("Test")
module.buy(test, 5)
Local script(second attempt)
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("Buy"))
local test = workspace:WaitForChild("Test")
module.buy(test, 5)
Module script(for server script)
local buyitem = {}
print("Before event!")
game.Players.PlayerAdded:Connect(function(plr)
print("Event called!")
function buyitem.buy(item, itemcost)
print("Creates a function.")
local cash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
print("Gets the cash value!")
if cash.Value >= itemcost then
print("Compares the cost")
cash.Value -= itemcost
print("Subtracts cash!")
local obj = Instance.new("ObjectValue")
print("Creates")
obj.Name = item.Name
print("Names")
obj.Value = item
print("Sets Value")
obj.Parent = plr.Inventory
print(obj.Name)
print("Parents")
print("Done Debugging!")
end
end
end)
return buyitem
Module script(for local script):
local buyitem = {}
print("Before event!")
print("Event called!")
function buyitem.buy(item, itemcost)
local plr = game.Players.LocalPlayer
print("Creates a function.")
local cash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
print("Gets the cash value!")
if cash.Value >= itemcost then
print("Compares the cost")
cash.Value -= itemcost
print("Subtracts cash!")
local obj = Instance.new("ObjectValue")
print("Creates")
obj.Name = item.Name
print("Names")
obj.Value = item
print("Sets Value")
obj.Parent = plr.Inventory
print(obj.Name)
print("Parents")
print("Done Debugging!")
end
end
return buyitem
I’m really wondering what’s gone wrong, and yes, I’ve swapped around the greater-than symbol, still no hope.