Hi, I’m making a game and I want to be able to store 2 seperate instances in 2 seperate tables for each player that fires the even shown below. However, after the player fires sequence 2, it will attempt to destroy the instance in the table and then set it to nil, but it doesn’t work. How can I make it work?
local t = {}
local t2 = {}
event.OnServerEvent:Connect(function(player, sequence)
if not table.find(t, player) then
t[player] = ServerStorage.Bari:WaitForChild("BariCylinder"):Clone()
t2[player] = Instance.new("ForceField", player.Character.HumanoidRootPart)
end
if sequence == 1 then
t[player].Parent = player.Character
t2[player].Visible = false
elseif sequence == 2 then
local DissapearGoal = {}
DissapearGoal.Transparency = 0
local TWInfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = TweenService:Create(t[player], TWInfo, DissapearGoal)
print(t[player])
tween:Play()
tween.Completed:Wait()
t[player]:Destroy()
t[player] = nil
t2[player]:Destroy()
end)
The only solution i’ve tried currently is debris service, not sure if it does much difference but it dosn’t work either.
edit: the tween doesn’t play either, but somehow the sciprt makes it past the tween.Completed:Wait()
edit 2: Okay, after a lot of debugging using print, i found out that whenever the event was being fired, at the part here:
if not table.find(t, player) then
t[player] = ServerStorage.Bari:WaitForChild("BariCylinder"):Clone()
t2[player] = Instance.new("ForceField", player.Character.HumanoidRootPart)
end
gets fired when i fire it the second time as well. Apparently, whenever I fire it, it can’t find the said t, player and it is nil. Why? If i fix this im sure it will work.