How can i make this script teleport to the part after Firing the Function again?

  1. What do you want to achieve?
    I want it to teleport to the part after reactivating the function again

  2. What is the issue?
    I don’t know how to implement it to be compatible with multiple players.

  3. What solutions have you tried so far?

    I tried to make the teleport function a global function so i can fire the Teleport function but when theres 2 players that tries to teleport it kinda get messes up such as the 2nd player will not be able to teleport once the 1st person reactivates it

Tried

local Cooldown = {}

return function(Player)
if not Cooldown[Player] == false then Teleport() return end
	Cooldown[Player] = true
	
	local Part = script.MeshPart:Clone()
	Part.CFrame = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3)
	Part.Parent = game.Workspace
	
	local Tween = game.TweenService:Create(Part, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = Part.CFrame*CFrame.new(0,0,-50)})
	Tween:Play()
	game.Debris:AddItem(Part, 5)
	local Teleported = false
	
	function Teleport()
		if Teleported == false then
		Teleported = true
		Player.Character.HumanoidRootPart.CFrame = Part.CFrame
		end
	end
	
	Tween.Completed:Wait()
	if Teleported == false then
		Teleported = true
		Teleport()
	end
	
	wait(2)
	Cooldown[Player] = false
	
end

Original
local Cooldown = {}

return function(Player)
if not Cooldown[Player] == false then --[[Teleport Script that i don't know how to implement]] return end
	Cooldown[Player] = true
	
	local Part = script.MeshPart:Clone()
	Part.CFrame = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3)
	Part.Parent = game.Workspace
	
	local Tween = game.TweenService:Create(Part, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = Part.CFrame*CFrame.new(0,0,-50)})
	Tween:Play()
	game.Debris:AddItem(Part, 5)
	local Teleported = false
	
	local function Teleport()
		Teleported = true
		Player.Character.HumanoidRootPart.CFrame = Part.CFrame
	end
	
	Tween.Completed:Wait()
	if Teleported == false then
		Teleported = true
		Teleport()
	end
	
	wait(2)
	Cooldown[Player] = false
	
end

What’s “it”? You need to be more specific.

i’m still a beginner so i might not be able to give a better explanation than that as i thought once people sees the script they’d be able to determine what i’m trying to do

Could you explain a little more on what you’re trying to do?

i want the script to be able to fire the “local function teleport()” using this

Summary
if not Cooldown[Player] == false then teleportscriptheretthatidontknowhowtoimplement() return end 

or something around it I just need the script to be able to teleport players to the part once they reactivate the function again without messing up as I tried to make it a global function but when someone reactivates that global function it didn’t allow the other players to teleport to the part that is being tweened or the part they shooted out.

You should define the Teleport function outside of the main function and in the main function when you want to invoke Teleport you will pass the Player as an argument.

Also you don’t need to create a Part to save the target CFrame, you should define it as a variable.

How will i find the part they shooted out or the part they’re suppose to Teleport to if i do that?

Well if you really needed the part then it’s fine to keep, but all necessary teleporting data like the player and stuff can be passed into the function, you don’t need to define a new function every time something happens.