#Quick question about how Local Variables created in Modules work.

1 messages · Page 1 of 1 (latest)

crisp sierra
#

If I were to create a local variable in a module, like "local boolean = false" in a module, would all players share that variable when using the module? Like for example if Player 1 were to change boolean to be true, would Player 2 also see the local boolean as set to true? Or would Player 2's boolean still be false while Player 1 has it set to true?

vital mantle
crisp sierra
#

Ah ok thank you

crisp sierra
#

I've been trying to test my code and for some reason, one player using a module works but the player who uses it afterwards doesn't work entirely correctly

#

what's supposed to happen is it creates particle effects on the person who ran the module and initiate an animation along with setting walk speed to 0 and turning off the camera turning

#

but the second player just reactivates the particles on the first person who used it and it doesn't unlock the second player from being stuck in place

vital mantle
crisp sierra
#

like cloning a set of particle effects?

vital mantle
crisp sierra
#

Oh

vital mantle
#

If you share the code then I can tell you

crisp sierra
#

Ok

#

I'll see if it fits in a message

#

oh it compressed it

vital mantle
#

If this is running on the server, the server will use the same module.

crisp sierra
#

yeah I'll try chunking it into pieces

#
module.Start = function(Player: Player)
        
    if game.ReplicatedStorage.PlayerData:FindFirstChild(Player.Name).UniqueVals.UniqueBool.Value == false and isTransforming == false then
        game.ReplicatedStorage.PlayerData:FindFirstChild(Player.Name).UniqueVals.UniqueBool.Value = true
        module.Transform(Player)
    end
    
    
    --    if game.ReplicatedStorage.PlayerData:FindFirstChild(Player.Name).UniqueVals.UniqueBool.Value == false and humanoid.Health >= (humanoid.MaxHealth/2) and isTransforming == false then
        --module.CreateBaseAura(Player)
        --module.BaseStart(Player)
--     end
    
    
end

module.End = function(Player: Player)
    
    
    if game.ReplicatedStorage.PlayerData:FindFirstChild(Player.Name).UniqueVals.UniqueBool.Value == false and isTransforming == false then
        module.BaseEnd(Player)
    end
end
vital mantle
crisp sierra
#

Yeah

#

That's just the part that starts the transformation

vital mantle
#

Okay, so like I said, the server will have the same instance of the module.

#

So the server is using this same module any time you require it

crisp sierra
#

so should I not be using require?

vital mantle
#

No you should be. It's fine. But you have to do things differently.

crisp sierra
#

Would it break if the script using require was a module script?

#

it activates using a module attached to a thing that fires whenever the specific button is pressed

vital mantle
#

All module scripts must return one value. require runs the module and stores whatever was returned. Any future calls to require will just give the thing that was returned when it was first run.

crisp sierra
#

Ok

sharp shuttleBOT
#

studio** You are now Level 6! **studio

crisp sierra
#
module.Charge.Begin = function(Player: Player)
local character = game.ReplicatedStorage.PlayerData:WaitForChild(Player.Name):WaitForChild("Character").Value
    if script.Charges:FindFirstChild(character) then
        local ChargeHandler = require(script.Charges:FindFirstChild(character))
        ChargeHandler.Start(Player)
    end
end

module.Charge.End = function(Player: Player)
    local character = game.ReplicatedStorage.PlayerData:WaitForChild(Player.Name):WaitForChild("Character").Value
    if script.Charges:FindFirstChild(character) then
        local ChargeHandler = require(script.Charges:FindFirstChild(character))
        ChargeHandler.End(Player)
    end
end
#

So when this is run a second time, because I used require, it would run using the first player who used it and not the person who used it afterward?

vital mantle
crisp sierra
#

Yes

#

as in the module this is all happening in? Because it does get required by the script that calls it when an input happens

#

so the module this is in gets required and then these modules it's calling are also required

vital mantle
crisp sierra
#

Oh

#

So should I remove the require part?

vital mantle
crisp sierra
#

charge handler

#

because it's the module with the actual code for the animation and effects and stuff

vital mantle
crisp sierra
#

it's not cloned, at least I don't think it is, and it gets retrieved from the same spot each time

#

but it differs from other inputs that start attacks or animations because those have handlers that get called and then direct to the right character attack module

vital mantle
crisp sierra
#

It’s supposed to activate separately for each individual

#

Like one player transforming shouldn’t affect how another transforms

#

So unique in however that way is

vital mantle
#

by that I mean the module will be copied over to the character when they spawn, so you can just require the module from the player's Character

crisp sierra
#

Should I be putting all modules that activate player specific things in starter character?

crisp sierra
vital mantle
crisp sierra
#

I forgot who told me but someone else said that exploiters can only change stuff in the character

crisp sierra
#

Ok

#

I’ll try and move it over to playerscripts

#

It won’t cause too much lag though right?

vital mantle
# crisp sierra Ah

My suggestion is just do this differently. Use tables to separate variables into a per-player basis, and have a module function that just does what it needs to for the given player

crisp sierra
#

Because the control module is the parent of all the separate fighter modules that are all different for each of my playable characters

crisp sierra
#

That makes sense

vital mantle
crisp sierra
#

Ok

#

Thank you