You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want to remove an entry from a dictionary inside of a modulescript from a server script.
- What is the issue? Include screenshots / videos if possible!
I cant do this as using inplayers.remove(inplayers, table.find(inplayers, player))
(Line 69 leavehandler) gives a Workspace.leave handler:69: attempt to call a nil value
error
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried many methods to do this, none have worked (with my implimentation)
--leavehandler
fastpass = function(player, tagged)
print('tagged')
if tagged.Character.values.tagged.Value == false then
print('not it')
local char = tagged.Character --tagged PLR
--if tagged.Name == us.Name then
local ci = game.Workspace.CurrentIT
ci.Value = tagged
char.Humanoid.WalkSpeed = 30
local ss = game.ServerStorage
local la = "Left Arm"
local tnt = ss.TNT:Clone()
tnt.Parent = game.Workspace[char.Name]
local weld = Instance.new("WeldConstraint")
weld.Parent = char.pospart
--pos calc
local pospart = char.pospart
local pos = pospart.Position
--
local audio = Instance.new('Sound')
local explosion = game.ServerStorage.explosion:Clone()
explosion.Parent = char.Torso
explosion.Enabled = true
audio.SoundId = "rbxassetid://138014729"
audio.Parent = char
audio.RollOffMaxDistance = 15
audio.RollOffMinDistance = 1
audio:Play()
tnt.Position = pos
weld.Part0 = char.pospart
char.values.tagged.Value = true
weld.Part1 = tnt
tnt.Orientation = Vector3.new(char.Torso.Orientation.X,char.Torso.Orientation.Y,char.Torso.Orientation.Z)
wait(1)
audio:Destroy()
explosion:Destroy()
wait(5)
--end
end
end
local Players = game:GetService("Players")
print('players defined outside of function')
popupmanager = require(game.ServerStorage.ModuleScript)
print('popupmanager defined outside of function')
Players.PlayerRemoving:Connect(function(player)
--repeat
wait()
print('leave fired')
local char = player.Character
print('char defined indide of function')
print(game.Workspace.CurrentIT.Value.ClassName)
if game.Workspace.CurrentIT.Value == player or game.Workspace.CurrentIT.Value.Name == player.Name then
print(player.Name .. " left lol")
local players = game.Players:GetPlayers()
print('players defined indide of function')
local it = players[math.random(#players)]
print('it defined indide of function as ' .. it.Name)
print(it.Character.values.playing.Value)
if it.Character.values.playing.Value == true and it.Character.Name ~= player.Name then
print('sorry man lolll')
fastpass(char,it)
local usetable = require(game.ServerStorage.rounds)
local inplayers = usetable.inplayers
print(inplayers)
print(player)
inplayers.remove(inplayers, table.find(inplayers, player))
popupmanager.PopUp(it, "sorry that im lazy", "sorry, i didnt have much patience to make a proper leave handler for the it player, so it just passes to a random person. and you were picked. \nl sorry not sorry, Cryptic.")
game.Workspace.CurrentIT.Value = it
elseif it.Character.Name == player.Name then
print("that didnt work how i wanted it to")
print("old ".. it)
local players = game.Players:GetPlayers()
local it = players[math.random(#players)]
print(print("new ".. it))
return
end
end
--until game.Workspace.CurrentIT.Value ~= player
end)
--modulescript "rounds"
--!nolint explosion
--!nocheck
local Rounds = {}
function Rounds.StartRound(countdown, playercount)
local players = game.Players:GetPlayers()
local inplayers = players
local function set(player)
local ss = game.ServerStorage
local la = "Left Arm"
local plr = player
local tnt = ss.TNT:Clone()
tnt.Parent = game.Workspace[player.Name]
local weld = Instance.new("WeldConstraint")
weld.Parent = plr.Character:WaitForChild('pospart')
local val = plr.Character.values:WaitForChild('tagged')
val.Value = true
plr.Character.Humanoid.WalkSpeed = 30
--pos calc
local pospart = plr.Character:WaitForChild('pospart')
local pos = pospart.Position
--
tnt.Position = pos
weld.Part0 = plr.Character.pospart
weld.Part1 = tnt
end
local function Explode(player)
local players = game.Players:GetPlayers()
local explosion = game.ServerStorage.explosion:Clone()
game.Workspace[player.Name].values.playing.Value = false
local it = inplayers[math.random(#inplayers)]
if it ~= player and #inplayers ~= 2 then
if player.ClassName == "Player" then
local charf = player.Character
_G.pass(charf,it)
elseif player.ClassName == "Model" then
_G.pass(player,it)
elseif #inplayers == 2 then
game.Workspace[it.Name].HumanoidRootPart.CFrame = game.Workspace.SpawnTP.CFrame
it.values.playing = false
end
game.Workspace[player.Name].HumanoidRootPart.CFrame = game.Workspace.SpawnTP.CFrame
end
end
local popupmanager = require(game.ServerStorage.ModuleScript)
local timer = game.Workspace.Timer
local players = game.Players:GetPlayers()
repeat
wait(1)
timer.Value = countdown .. (' Seconds Until Next Round!')
countdown = countdown - 1
until countdown <= 0
local it = players[math.random(1, #players)]
set(it)
for i,v in pairs(game.Players:GetChildren()) do
v.Character.values.playing.Value = true
game.Workspace[v.Name].HumanoidRootPart.CFrame = game.Workspace.indev.spawns.gametp.CFrame
end
local ci = game.Workspace.CurrentIT
local itchar = game.Workspace[it.Name]
print(itchar)
ci.Value = itchar
print("IT : "..(it.Name))
Rounds.inplayers = players
local t = 40
repeat
repeat
wait(1)
timer.Value = t .. (' Seconds Until Explosion!')
t = t - 1
until t <= 0
t = 40 --inplayers * 10 + 5
local ci = game.Workspace.CurrentIT
print(inplayers)
Explode(ci.Value)
print(ci.Value)table.remove(inplayers, table.find(inplayers, ci.Value))
print(#inplayers)
print(inplayers)
until #inplayers <= 1
itchar = game.Workspace[ci.Value.Name]
local tnt = itchar.TNT
tnt:Destroy()
for i,v in pairs(game.Players:GetChildren()) do
game.Workspace[v.Name].HumanoidRootPart.CFrame = game.Workspace.SpawnTP.CFrame
itchar = game.Workspace[ci.Value.Name]
local winner = inplayers[1]
itchar.values.tagged.Value = false
itchar.values.playing.Value = false
winner.Character.values.playing.Value = false
winner.Character.values.tagged.Value = false
timer.Value = "Game Finished!"
popupmanager.PopUp(v, 'Winner!', winner.Name .. " Won the game!")
end
end
return Rounds