I have a ModuleScript that shows a UI and starts a countdown when called. Once the timer runs out, it is supposed to cut off and pick the player who was picking, but it keeps picking nothing.
The ModuleScript is in the PlayerGui, under the path game.Players.[player].PlayerGui.GameUI.ChoosePlayer.LoadPlayer It is called from ServerScriptService.
Script:
local module = {}
function module:load(playerList) -- array of players in round
for i, data in pairs(playerList) do
local name, platform = table.unpack(data)
local buttonName = "P" ..i
if script.Parent.Buttons:FindFirstChild(buttonName) then
script.Parent.Buttons:FindFirstChild(buttonName).trueUserName.Value = name.Name
script.Parent.Buttons:FindFirstChild(buttonName).Visible = true
end
end
for timeLeft = 10, 0, -1 do
if script.Parent.ChosenPlayer.Value == "" and script.Parent.TimedOut.Value == false then
script.Parent.TimeToChoose.Text = tostring(timeLeft)
task.wait(1)
end
end
if script.Parent.TimedOut.Value == false then
print('chosen')
local returnVal = script.Parent.ChosenPlayer.Value
script.Parent.ChosenPlayer.Value = ""
return returnVal
else
print('self')
return script.Parent.Parent.Parent.Parent.Name
end
end
return module
You can’t call module scripts from a server script and expect to return a value from the client. When you require the module from a server script in runs on the server. Use a remote event to get the selection
It’s not getting a value from the client. It’s entirely server-based. Picking with it works, but it’s supposed to pick the player it’s parented to (the script.Parent.Parent.Parent.Parent.Name) and return that to the server. I’m not using any LocalScripts.
It might also be an issue with the module in ServerScriptService:
function module:runRound(chosen,playersInGame)
local playerTable = playersInGame[chosen]
local name, platform = table.unpack(playerTable)
module:setServerText(name.Name .." <b>is choosing who to damage.</b>")
if name then
name.PlayerGui.GameUI.ChoosePlayer:TweenPosition(UDim2.new(0,0,1,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,0.5,true)
chosen = require(name.PlayerGui.GameUI.ChoosePlayer.LoadPlayers):load(playersInGame)
repeat task.wait() until chosen
name.PlayerGui.GameUI.ChoosePlayer:TweenPosition(UDim2.new(0,0,1.8,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,0.5,true)
else
chosen = nil
end
if chosen then
module:setServerText(name.Name .." <b>chose for</b> " ..chosen .." <b>to take damage.</b>")
task.wait(5)
local result = math.random(0,10)
spinner:FireAllClients(workspace.RollRoom.Spinner.SpinScript,result)
task.wait(3)
module:setServerText(chosen .." <b>lost</b> " ..result .." <b>health.</b>")
print('fired')
game.Players:FindFirstChild(chosen).Character.Humanoid.Health -= result
wait(3)
if game.Players:FindFirstChild(chosen).Character.Humanoid.Health <= 0 then
table.remove(playersInGame,table.find(playersInGame,playerTable))
module:setServerText(chosen .." <b>has died.</b>")
end
elseif chosen == nil then
chosen = "gameChooseRandom"
end
return chosen
end