Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't I access the Player in a module script from this setup?

Asked by 6 years ago

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:

01local key = "z"
02local Mouse = game.Players.LocalPlayer:GetMouse()
03local Player = game.Players.LocalPlayer
04SpellDisableCheck = false
05Mouse.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
10    end
11end)

Module:

01local WaterMagic = {}
02function WaterMagic.Slicer(Player, damage)
03    print("z pressed")
04    local Animation = Instance.new("Animation")
05    Animation.AnimationId = "http://www.roblox.com/asset/?id=357408908"
06    local track = Player.Character.Humanoid:LoadAnimation(Animation)
07    track:Play()
08    local Torso = Player.Character.Torso
09    local rand = {0, 15, -15, 45, -45}
10    local Part = game.ReplicatedStorage.Resources.Parts:FindFirstChild("WaterSlicer")
11    for i = 1, 10 do
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)
15        f.Name = "Creator"
View all 33 lines...

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.

1local EventStore = game.ReplicatedStorage.Resources.MagicEvents
2local Modules = game.ServerStorage.Magics
3---Water Magic
4local Water = require(Modules.Water)
5local slicer = Instance.new("RemoteEvent", EventStore)
6slicer.Name = "WaterSlicer"
7slicer.OnServerEvent:Connect(function(Player, Damage)
8    Water.Slicer()
9end)
1
can we see what the output says? DragonSkyye 517 — 6y
1
can we see what the output says? DragonSkyye 517 — 6y
0
What does the error say? At which line in your code is it? Amiaa16 3227 — 6y
0
Line 6 of the modulescript - 'attempt to index player was nil' EvilMessor 9 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You're not passing in the arguments to the ModuleScript. Look at line 8 in the server script. You simply call Water.Slicer() instead of Water.Slicer(Player, damage), which is exactly why the ModuleScript can't find a player object.

Ad

Answer this question