How save players' Position that are around you with table

What I am trying to achieve?
When the chant is fully played the players around the caster will be detected by touched and then I weld constraint them to the hitbox then move them to another dimension same goes for the caster.After moving them the explosion will deal 80 damage to the players that are in the dimension other than the caster by using another touched connect.After that I will move the hitbox that the players are welded constraint back to the original position.
(Table would be useful instead of using this inefficient way.)

Issue:
Sometimes the players that are teleported to the dimension will not get damage.
I think it could be weld constraint,when they are welded they wont get damage?
When they do get damage,they die.My touched script should had prevented from damaging players that already been damaged.

Welding players to the hitbox script:

local Hits = {}
hitbox.Touched:Connect(function(Hit)
if Hits[Hit.Parent.Name] then
return
end
if Hit.Parent:FindFirstChild(“Iframes”) then
return
end
if Hit.Parent.Name == player.Name then return end
Hits[Hit.Parent.Name] = true
local StunHandler = require(game.ReplicatedStorage.StunHandlerV2)

		StunHandler.Stun(Hit.Parent.Humanoid, 38.7, Hit.Parent.CanAttack)
		local stun = game.ReplicatedStorage.ExtraFolder.StunnedBillBoard:Clone()
		stun.Parent = Hit.Parent.Head
		game.Debris:AddItem(stun,38.7)--change-->>	stuns for 5 seconds
		
		local stick = Instance.new("WeldConstraint",hitbox)
		stick.Part0 = hitbox
		stick.Part1 = Hit.Parent.HumanoidRootPart
		game.Debris:AddItem(stick,40)
	end)

Damaging Part when players teleported to the dimension:

local Hits = {}
part1.Touched:Connect(function(Hit)
if Hits[Hit.Parent.Name] then
return
end
if Hit.Parent:FindFirstChild(“Iframes”) then
return
end

				Hits[Hit.Parent.Name] = true
				Hit.Parent.Humanoid:TakeDamage(20)
				local stick = Instance.new("WeldConstraint",player.Character:FindFirstChild("CoverMarble"))
				stick.Part0 = player.Character:FindFirstChild("CoverMarble")
				stick.Part1 = Hit.Parent.HumanoidRootPart

			end)

From what I know from testing multiple times,when the touch does work the players wont be brought out of the dimension.But when the players didnt receive the damage they will get teleported out of the dimension.The code itself is really inconsistence.

To be honest I dont really know how to use table and I am pretty sure for the teleporting back out of the dimension can use tables but I dont know how.Its indeed much efficient than the way I am using right now.
File too big so I had no choice(I was struggling to go to the dimension map in the video so bare with me lol)

Edited

I found few lines of codes for teleporting back with a table but the problem it applies to all players in game not those nearby the caster of the move.When teleporting back it also applies to all players not the ones being affected by the move.

local playerLocations = {}
local PlayerService = game:GetService(“Players”)
for _, player in pairs(PlayerService:GetPlayers()) do
playerLocations[player] = player.Character:GetPrimaryPartCFrame()
end

	for _, player in pairs(PlayerService:GetPlayers()) do
		player.Character:SetPrimaryPartCFrame(playerLocations[player])
	end

Maybe someone can help me or teach me how do I save the players’ position around the caster in a table then after a certain time the players will be teleported back to the saved position in the table.(Make sure its not all players only the ones that are close by the caster.)

1 Like

If I understand you correctly, you want to make kill part?

1 Like

Not kill,just damaged them 80 damage then teleport them back out of the dimension

1 Like

Oh, then sorry I don’t know how to make it. I’m a still a bit new to scripting

1 Like

You will probably have an idea onto how to save the players’ positions with this link.

2 Likes

Try this…

  1. iterate through all players, and create a table of the ones in range (teleport table)
  2. teleport only players on this table
  3. damage only players on the table
  4. teleport back the players on the table
2 Likes

Okay I make the table first then I make another touched part that detects player in range.But how do I reference the players in range and then change their humanoidrootpart position?

Code:
local TableOfOriginalPositions = {}–I make the table
hitbox.Touched:Connect(function(Hit)

	table.insert(Hit.Parent.Name,Hit.Parent.HumanoidRootPart.Position)--I save the position and the player name
end)
task.wait(1)

–this part i dunno how to make them tp back and dunno how to reference the hit.Parent

Something have to do with “for i, in pairs” or something like that right?Just guessing

1 Like

Why are you using a hitbox to detect range? What shape is the ‘damage’ object? Is it anyone who is close to the center of the effect?

2 Likes

I mean using hitbox is the only way for me to detect players in range so I can insert them into the table

1 Like

Its not the only way, if its a sphere area, or a cylinder area, or even a cube area, you can use a mathematical formula.

What is the shape of the region that will do damage?

2 Likes

the shape of the region is a circle

1 Like
for _,player in pairs(tableOfPlayers) do
  if (player.Character.PrimaryPart.Position - CircleCenterPosition).Magnitude < RadiusOfCircle then
    player.Character.Health = player.Character.Health - DamageTakenFromCircle
  end
end
2 Likes

I am not sure what to put as the circle center position,am i supposed to put like where the range position will be?If so i typed player.Character.HumanoidRootPart.CFrame

1 Like

I assume the damage is coming from a npc or player casting a spell?

CastingPlayer.Character.HumanoidRootPart.CFrame.Position
2 Likes

the caster is the player and the player deals 80 damage to the players around him.

1 Like

I feel like i am really close to getting this right,
(Something is not right doe…)
code:

local playerLocations = {}
for _,player in pairs(playerLocations) do
if (player.Character.PrimaryPart.Position - player.Character.HumanoidRootPart.CFrame.Position).Magnitude < 1000 then
player.Character.Health = player.Character.Health - 80
playerLocations[player] = player.Character:GetPrimaryPartCFrame()–this saves player position into the table
end
end

	for _,player in pairs(playerLocations) do
		player.Character:SetPrimaryPartCFrame(playerLocations[player])--this tps the player in table back to the position thats saved in the table
	end

I tested it and it didnt do anything,didnt even damage or even say any error in the console

1 Like

change this…
image
to…
for _,player in pairs(game.Players:GetPlayers()) do

this will loop through all the players in the game
So that you can determine if they are close enough to have damage done to them.

2 Likes

Okay thank you,it worked perfectly just one last problem.

The script didnt teleport the player back even though theres no error.(Damage is still taken and in console no error)

When i normally use the code together it works but when I used it in this way it wouldnt
Example:
game.ReplicatedStorage.ServantsRemotes.Emiya.TraceOnRemote.OnServerEvent:Connect(function(player,onoff)
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

elseif onoff == ‘Off’ then
local caster = player.Name
for _,player in pairs(game.Players:GetPlayers()) do
player.Character:SetPrimaryPartCFrame(playerLocations[player])
–if player.Name == caster then return end
player.Character.Humanoid.Health = player.Character.Humanoid.Health - 80
end
end)

When i use it like this it no work and I have no idea.

1 Like

Can you please use the “```” and format the code so I can read it?
Thanks.

1 Like