I am not sure why my function in a module script isn’t running and i’m not sure what is causing it.
so whenever the player clicks play, it will fire an event to the server. When the event is called and the server receives it, it is supposed to run a function in a module script. For some reason, it is not doing that.
All i know is that it isn’t the inRound value, because it is enabling and disabling the Guis.
Script for the play button:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UI = player.PlayerGui
local round = game.ReplicatedStorage.Round
local inRound = round.inRound
local button = script.Parent
button.MouseButton1Click:Connect(function()
if inRound.Value == false then return end
game.ReplicatedStorage.GeneralEvents.TeamChange:FireServer()
UI.Rounds.Enabled = true
UI.Menu.Enabled = false
end)
Script on Server:
local TEAM_H = require(script.teamsHandler)
local replicated = game.ReplicatedStorage
local GE = replicated.GeneralEvents
local teamChange = GE.TeamChange
teamChange.OnServerEvent:Connect(TEAM_H.onEvent)
function on module script (the one that isn’t being called because doesn’t print here! ):
function module.onEvent(player)
print("here!")
local humRoot = player.Character
local playersOnRed = redTeam:GetPlayers()
local playersOnBlue = blueTeam:GetPlayers()
numberInRed = #playersOnRed
numberInBlue = #playersOnBlue
print("here!")
local function setTeam(team)
player.Team = game.Teams[team]
if team == "Red" then
table.insert(referenceRed, player.Name)
else
table.insert(referenceBlue, player.Name)
end
for i, v in pairs(workspace:GetChildren()) do
if v.Name == team then
humRoot:SetPrimaryPartCFrame(v.CFrame)
end
end
end
print("here!")
if numberInRed > numberInBlue then
setTeam("Blue")
elseif numberInBlue > numberInRed then
setTeam("Red")
else
local randomNumber = math.random(1, 2)
if randomNumber == 2 then
setTeam("Red")
else
setTeam("Blue")
end
end
print("here!")
enable:FireClient(player, "Rounds")
player.Character.Humanoid.WalkSpeed = 16
end