I Have a module script with variables shared across functions. I want these variables to be accessed by both functions but for individual players (because more then one person will use this module at a time). The issue is that since this module is accessed by both a server end and client end it gets messy with variables. More or less my problem is that I don’t know the right way to use my variables since I’ve barely used module scripts before. I’ve kind of written myself into a hole, but this function has to run through a module.
thanks everyone for reading and looking through my messy code lol.
Here is how I wrote my module:
local module = {}
Animation = script.Animation
local Anim, Anim2
local a
local rushing = false
local TimeSinceStart,readytostop,readytostop2
function module:Fire(server,Script,Player,r)
if server then
readytostop = false
wait(.2)
Anim = Player.Character.Controller:LoadAnimation(Animation)
Anim:Play()
readytostop = true
else
readytostop2 = false
TimeSinceStart = time()
rushing = true
wait(.2)
a = Player.Character.RightLowerArm.Touched:connect(function(h)
-- just some damage stuff
end)
readytostop2 = true
repeat wait(.01)
if (time() - TimeSinceStart) > 6 then
rushing = false
a:Disconnect()
r:FireServer("EndForce") -- this forces the server to run module:End()
print("Tried to stop")
break
end
until rushing == false
end
end
function module:End(server,Script,Player,r)
if server then
repeat wait() until readytostop == true
Anim:Stop()
else
repeat wait() until readytostop2 == true
rushing = false
a:Disconnect()
end
end
return module