What Am I Trying To Achieve?
I am currently making a magic spell move that makes the caster recites a chant then teleport players around the caster into a dimension.It is a cutscene move,before the move finishes the caster and the players that been teleported into the dimension would be back at the position before the spell was casted.
Problem/Issue:
I created a few forum before this that is also about this one single same move.
First when the caster uses the move he recites a chant while players’ position that are around him will be placed into a dictionary.But the issue appears,my script for this cutscene is separated into sections,what I mean by that is like
Example:
game.ReplicatedStorage.ExampleRemote:Connect(function(player,section)
if section == “section1” then
–the first code that makes the table and insert all the players’s position around the caster into it
end
if section == “section2” then
–the line of code that needs the table from section 1 so it can teleports the players that are in the dictionary back to the position before the spell was casted.
end
end)
I couldnt reference the dictionary from section 1 to section 2 so I used the BindableFunction with the help of the last forum I posted.After I managed to get an answer from the forum and solve it the real problem comes in.Whenever I try printing the dictionary out it says nil and when the players that got teleport back by the section 2 code they always ended up in the wrong position that were once in before the spell was casted.The dictionary was completely empty???
I tried and fix but in the end I couldnt find out why.
Codes:
The code that creates the dictionary and stores the players’ position around the caster(including the caster position too)
Text:
local playerLocations = {}
for _,player in pairs(game.Players:GetPlayers()) do
if (player.Character.PrimaryPart.Position - player.Character.HumanoidRootPart.CFrame.Position).Magnitude < 100 then
playerLocations[player] = player.Character:GetPrimaryPartCFrame()
end
end
script.Function:Invoke(playerLocations)
The code that teleports players back to the position before the spell was casted:
Text:
local caster = player.Name
local playerLocations = {}
script.Function.OnInvoke = function(t1)
playerLocations = t1
for _,player in pairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.Position = Vector3.new(playerLocations[player])
–playerLocations[player]
if player.Name == caster then return end
player.Character.Humanoid.Health = player.Character.Humanoid.Health - 80
end
end
end
end)
Video:(Lagged at the start for a few seconds)
Any help would be appreciated