Why can't I access the Player in a module script from this setup?
Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
When a player presses a key, it fires an event. The event runs whatever code is in the modulescript. But I always get the same error - about the Player, no matter how I go about it.
Client:
02 | local Mouse = game.Players.LocalPlayer:GetMouse() |
03 | local Player = game.Players.LocalPlayer |
04 | SpellDisableCheck = false |
05 | Mouse.KeyDown:Connect( function (Key) |
06 | if Key:lower() = = key and SpellDisableCheck = = false then |
07 | SpellDisableCheck = true |
08 | game.ReplicatedStorage.Resources.MagicEvents.WaterSlicer:FireServer(Player, script.Damage) |
09 | SpellDisableCheck = false |
Module:
02 | function WaterMagic.Slicer(Player, damage) |
04 | local Animation = Instance.new( "Animation" ) |
06 | local track = Player.Character.Humanoid:LoadAnimation(Animation) |
08 | local Torso = Player.Character.Torso |
09 | local rand = { 0 , 15 , - 15 , 45 , - 45 } |
10 | local Part = game.ReplicatedStorage.Resources.Parts:FindFirstChild( "WaterSlicer" ) |
12 | local b = Part:Clone() |
13 | b.CFrame = Torso.CFrame * CFrame.new(math.random(- 3 , 3 ), math.random( 0 , 3 ), - 3 ) * CFrame.Angles( 180 , math.rad(rand [ math.random( 1 , #rand) ] ), 0 ) |
14 | local f = Instance.new( "StringValue" , damage) |
17 | local Damage = Instance.new( "IntValue" , damage) |
18 | Damage.Name = "Damage" |
19 | Damage.Value = 1 + (game.ReplicatedStorage.Resources.Remotes.Functions.GetPlayerStrength:InvokeServer() / 100 ) |
20 | damage.Disabled = false |
21 | local v = Instance.new( "BodyVelocity" , b) |
22 | v.maxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
23 | v.velocity = Torso.CFrame.lookVector * 125 |
25 | game:GetService( "Debris" ):AddItem(b, 4 ) |
The serverscript is basically creating a remotevent which requires the module script, and runs the respective function. Just incase I explained this bad, here is the serverscript.
1 | local EventStore = game.ReplicatedStorage.Resources.MagicEvents |
2 | local Modules = game.ServerStorage.Magics |
4 | local Water = require(Modules.Water) |
5 | local slicer = Instance.new( "RemoteEvent" , EventStore) |
6 | slicer.Name = "WaterSlicer" |
7 | slicer.OnServerEvent:Connect( function (Player, Damage) |