The module script & script I made both work in studio, but not ingame (the script I presume because it can't call the module script because of the error in the module script).
Module script:
local module = {} local player = game.Players:WaitForChild("LocalPlayer") local leaderstats = player:WaitForChild("leaderstats") module.giveChickenEaten = function(chicken, chickenIntValue, biteAmountInt) --2 --1 print("Calculating chicken eaten...") print(chickenIntValue) leaderstats["Chicken Eaten"].Value = leaderstats["Chicken Eaten"].Value + chickenIntValue biteAmountInt.Value = biteAmountInt.Value - 1 print(biteAmountInt.Value) if biteAmountInt.Value == 0 then chicken:Destroy() end end return module
Script (located inside a tool)
local Tool = script.Parent; enabled = true function onActivated(player) if not enabled then return end enabled = false Tool.GripForward = Vector3.new(0.675, -0.675, -0.3) Tool.GripPos = Vector3.new(0.4, -0.59, 1.1) Tool.GripRight = Vector3.new(0.212, -0.212, 0.954) Tool.GripUp = Vector3.new(0.707, 0.707, 0) wait(.8) local h = Tool.Parent:FindFirstChild("Humanoid") if (h ~= nil) then if (h.MaxHealth > h.Health + 1.6) then h.Health = h.Health + 1.6 else h.Health = h.MaxHealth end end Tool.GripForward = Vector3.new(-0.976,0,-0.217) Tool.GripPos = Vector3.new(0, -0.4, 0) Tool.GripRight = Vector3.new(0.217,0,-0.976) Tool.GripUp = Vector3.new(0,1,0) --where i want to activate the modulescript local module1 = require(game.ReplicatedStorage.ModuleScript) module1.giveChickenEaten(script.Parent, script.Parent.coldFriedChickenValue.Value, script.Parent.biteAmount) enabled = true end script.Parent.Activated:connect(onActivated)
Your script doesn't work because the module script does not access players. Instead pass player = game.Players.LocalPlayer
to the module script.
-- Module Script Function module.giveChickenEaten = function(player,chicken, chickenIntValue, biteAmountInt) print("Calculating chicken eaten...") print(chickenIntValue) leaderstats["Chicken Eaten"].Value = leaderstats["Chicken Eaten"].Value + chickenIntValue biteAmountInt.Value = biteAmountInt.Value - 1 print(biteAmountInt.Value) if biteAmountInt.Value == 0 then chicken:Destroy() end end
--Script located inside a tool local player = script.Parent.Parent local module1 = require(game.ReplicatedStorage.ModuleScript) --where the module script is activated module1.giveChickenEaten(player,script.Parent, script.Parent.coldFriedChickenValue.Value, script.Parent.biteAmount)