I’ve encountered an issue where a ModuleScript of mine runs the entire module instead of an invoked function.
ModuleScript:
local replicatedstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local assets = replicatedstorage.Assets
local module = {}
function module.claimball(character, football)
local hrp = character.HumanoidRootPart
local player = players:GetPlayerFromCharacter(character)
if football:GetAttribute("Owner") == character.Name then return end
print("claimed")
football:SetAttribute("Owner", character.Name)
football.CanCollide = false
football.Anchored = false
football.Parent = workspace
local cross = assets.Cross:Clone()
local weld = Instance.new("WeldConstraint")
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {character, football}
local ray = workspace:Raycast(hrp.Position, (hrp.CFrame.UpVector*-300),params)
if ray then
cross.Position = ray.Position + Vector3.new(0,0.25,0)
end
weld.Part0 = cross
weld.Part1 = hrp
weld.Parent = weld.Part0
cross.SurfaceGui.ImageLabel.ImageColor3 = player.TeamColor.Color
cross.Parent = character
local offset = CFrame.new(0,-2.25, -2)
football.CFrame = hrp.CFrame * offset
local weld = Instance.new("WeldConstraint")
weld.Name = "Weld"
weld.Part0 = football
weld.Part1 = hrp
weld.Parent = weld.Part0
end
function module.shoot(character, football)
print("fired")
local hrp = character.HumanoidRootPart
football:SetAttribute("Owner", "")
if football:FindFirstChild("Weld") then
football.Weld:Destroy()
end
football.CanCollide = true
--local lv = Instance.new("LinearVelocity")
--lv.MaxForce = math.huge
--lv.VectorVelocity = hrp.CFrame.LookVector * 100
--lv.Attachment0 = football.Attachment
--lv.RelativeTo = Enum.ActuatorRelativeTo.World
--lv.Parent = football.Attachment
football.AssemblyLinearVelocity = hrp.CFrame.LookVector * football:GetMass() * 200 + Vector3.new(0,75,0)
end
return module
ServerScript:
local players = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local events = replicatedstorage.Events
local module = require(replicatedstorage.Football)
events.Shoot.OnServerEvent:Connect(function(player)
local character = player.Character
local owner = workspace.Football:GetAttribute("Owner")
if owner == character.Name then
print("server shoot")
module.shoot(character, workspace.Football)
end
end)
LocalScript:
local players = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local cas = game:GetService("ContextActionService")
local uis = game:GetService("UserInputService")
local events = replicatedstorage:WaitForChild("Events")
local shoot = events:WaitForChild("Shoot")
function shootball(actionname, inputstate, inputobject)
if inputstate == Enum.UserInputState.Begin then
print("client shoot")
shoot:FireServer()
end
end
cas:BindAction("Shoot", shootball, true, Enum.UserInputType.MouseButton1)
Everything seems to work fine when the ball is claimed, however, once the client clicks, the server runs the entire ModuleScript.
Under the player, there’s 2 effects because the code is run twice.
The first “claimed” is when the player comes in contact with the ball.
“client shoot” is when the player clicks on the screen.
“server shoot” is when the server gets invoked.
“fired” is when the ModuleScript.shoot() gets run.
“claimed” is fired again which is not supposed to.
Given that both “fired” and “claimed” are run when the server calls for .Shoot() function, I think that the entire ModuleScript is run which is why I’m confused. I’m pretty tired so I might’ve missed something obvious, sorry.


