I have two functions and I need to send this table to another function. How would I do this?
event.OnServerEvent:Connect(function(player)
local teams = game:GetService('Teams')
if player.Team == teams.Menu and player.Profile.Character.Value then -- make sure they are in the menu
player.Team = teams.Playing -- make there team playing
-- load in the player
local spawnPoint = workspace.Spawns:GetChildren()[1]
player.RespawnLocation = spawnPoint
player:LoadCharacter()
local lastChar = player.Character
local lastCharPivot = lastChar:GetPivot()
-- load the player in
local char = player.Profile.Character.Value.Char:Clone()
char.PrimaryPart.CFrame = lastChar.PrimaryPart.CFrame -- set primary cframe
char.PrimaryPart.Anchored = false
player.Character = char
player.Character.Parent = workspace
player.Character:PivotTo(lastCharPivot)
lastChar:Destroy()
local anims = loadAnims(player.Profile.Character.Value.Anims, player.Character.Humanoid) -- this is the table I need to send
print('Character loaded')
else
end
end)
-- this is the second function in the same script
event.OnServerEvent:Connect(function(player,typeOf)
print(typeOf)
local currentChar = player.Profile.Character
if currentChar.Value.Name == 'Gorilla' then
-- i need to get the table here
local event2 = game:GetService('ReplicatedStorage'):FindFirstChild('AttackEvents'):FindFirstChild('Gorilla')
event2:Fire(player,typeOf)
end
end)
When considering yes I could do this. BUT . . . Danggit there’s always a but isn’t there . . .
Anyhow this loads it fora certain player. If I were to have a global variable it would update that variable for every player therefore every player would have to use the same animations
I also cant return the table cause they are two separate function so I wont be able to get that table over to the second function
When I say Local-Global Variabke I mean it’s Global in the script, meaning it isn’t Global I’m for everything
And from what I know you can actually return the table
You can create a global table which store keys that contain the ‘anims’ table for each player. This way:
local playerAnims = {} -- Initiates your global table here
event.OnServerEvent:Connect(function(player)
local teams = game:GetService('Teams')
if player.Team == teams.Menu and player.Profile.Character.Value then -- make sure they are in the menu
player.Team = teams.Playing -- make there team playing
-- load in the player
local spawnPoint = workspace.Spawns:GetChildren()[1]
player.RespawnLocation = spawnPoint
player:LoadCharacter()
local lastChar = player.Character
local lastCharPivot = lastChar:GetPivot()
-- load the player in
local char = player.Profile.Character.Value.Char:Clone()
char.PrimaryPart.CFrame = lastChar.PrimaryPart.CFrame -- set primary cframe
char.PrimaryPart.Anchored = false
player.Character = char
player.Character.Parent = workspace
player.Character:PivotTo(lastCharPivot)
lastChar:Destroy()
local anims = loadAnims(player.Profile.Character.Value.Anims, player.Character.Humanoid) -- this is the table I need to send
playerAnims[player.UserId] = anims -- Adds a key to the table using the player's Id, which is unique to the player, then stores the 'anims' table in it
print('Character loaded')
else
end
end)
-- this is the second function in the same script
event.OnServerEvent:Connect(function(player,typeOf)
print(typeOf)
local currentChar = player.Profile.Character
if currentChar.Value.Name == 'Gorilla' then
local anims = playerAnims[player.UserId] -- This gets the 'anims' table for your player
local event2 = game:GetService('ReplicatedStorage'):FindFirstChild('AttackEvents'):FindFirstChild('Gorilla')
event2:Fire(player,typeOf)
end
end)
Yes this should probably work I will try it out later!
And I will keep in mind what @Necro_las said.
Ill have to use this everytime the player dies and leaves.
Cause I reload the anims everytime they die! Thank you
You only have to clear the player’s key when they leave the game, since as you reload them when they die, it will simply overwrite their key with the new anims.