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)

12 comments
The rest of the script won't work as a local script.
Convert it to filtering enabled using remoteEvents, what you were trying to do wouldn't work even if it could run from a module script since it's not a localscript.
However, you could also just fine the player by doing script.Parent.Parent
How would I activate the script after something happens (what happens is in a script, not localscript).
Do you mean the module script? If so call the function in the module script. If not, there are several ways. One way is to have it disabled then enable it with another script. Another way is to use remoteEvents and fireclient/fireserver. A final way is to use .Changed to see if a condition is changed and if that condition is changed then that portion of the script will execute.
I updated the question to show you what I mean
You already are activating it. Chances are it doesn't work in-game is because you're still using localplayer which only works with localscripts.
Yes, so how would I get around that?
Like I said, do local player = script.Parent.Parent I already edited my answer.
Alright, I put in the second part of code, but there's an error: 22:16:04.974 - Infinite yield possible on 'Workspace.Vid_eo:WaitForChild("leaderstats")'
That means that you are never creating "leaderstats"
Leaderstats isn’t in workspace, though