script.Parent.Touched:Once(function(hit)
local SpecificPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if SpecificPlayer then
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name == SpecificPlayer.Name then
continue
end
v.Character:PivotTo(SpecificPlayer.Character:WaitForChild("HumanoidRootPart").CFrame)
opened.Value = false
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
closeSound:Play()
end
end
end)
local PS = game:GetService("Players")
script.Parent.Touched:Once(function(hit: BasePart)
local char = hit:FindFirstAncestorWhichIsA("Model")
local player = char and PS:GetPlayerFromCharacter(char)
if player then
for _,targetPlayer: Player in ipairs(player:GetPlayers()) do
if not targetPlayer.Character or targetPlayer == player then
continue
end
local targetChar = targetPlayer.Character
targetChar:PivotTo(char:GetPivot())
end
end
end)
Sorry for the delayed response, Anyways This script works a little fine, the issue is that if there is just one player. for example, if the player is playing solo the entire function will not be activated. You need more than 1 player to make it active How can this be fixed?
here is the script
local frame = script.Parent.Parent
local closeSound = frame:WaitForChild("DoorClose")
local model = frame.Parent
local frameClose = model:WaitForChild("DoorFrameClose")
local frameOpen = model:WaitForChild("DoorFrameOpen")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")
script.Parent.Touched:Once(function(hit)
local SpecificPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if SpecificPlayer then
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name == SpecificPlayer.Name then
continue
end
v.Character:PivotTo(SpecificPlayer.Character:WaitForChild("HumanoidRootPart").CFrame)
opened.Value = false
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
closeSound:Play()
end
end
end)
I recommend you use :GetTouchingParts() instead of trusting .Touched as it may cause issues.
This is what I did:
local MaxAmountOfPlayers = 1 -- Sets the Max Amount of players who can be on it. ( I set it to one because I have no friends to test it with..)
local Players = game:GetService("Players") -- Get the Players
local PlayersTouchingPart = {}; -- This is our table to see who is touching it
function UpdateTable()
local ListOfPartsTouching = script.Parent:GetTouchingParts() -- Getting all the parts touching script.Parent
local Added = false
for _,player in pairs(Players:GetPlayers()) do -- Loop through players
local Character = player.Character or player.CharacterAdded:Wait() -- Get Character
local Hrp = Character.HumanoidRootPart -- Get HumanoidRootPart
for _, part in pairs(ListOfPartsTouching) do -- Loop through the touching parts list
if part.Parent:FindFirstChild("HumanoidRootPart") then -- Check if the part's parent has a HumanoidRootPart.
if part.Parent.HumanoidRootPart == Hrp then -- Compare the players and this parts HumanoidRootPart
if table.find(PlayersTouchingPart, Hrp) then -- Check if they are already in the table
Added = true -- Set added true
else
if #PlayersTouchingPart < MaxAmountOfPlayers then -- Check if the table is full
table.insert(PlayersTouchingPart, Hrp) -- Add them to the table
Added = true -- Set added true
end
end
end
end
end
if Added then -- Checking if they were added
Added = false
else
if not Added then -- They weren't added!
if table.find(PlayersTouchingPart, Hrp) then -- Check if they are in the table
table.remove(PlayersTouchingPart, table.find(PlayersTouchingPart, Hrp)) -- Yeet them from the table.
end
end
end
end
end
script.Parent.Touched:Connect(function() -- You have to have this to allow the :GetTouchingParts() to work.
end)
while task.wait(1) do -- I set mine up to a loop.
UpdateTable() -- Updates the table
if #PlayersTouchingPart == MaxAmountOfPlayers then -- Check if the Players on the Part is equal to the max.
-- Proceed with what you were doing
print(PlayersTouchingPart[1].Parent) -- This is how you get the first player's HumanoidRootPart who touched it
end
end
local Connection
Connection = script.Parent.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Player.Character and Player.Character.HumanoidRootPart then
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character and v ~= Player then
local NewPivot = v.Character:GetPivot() * CFrame.new(Player.Character.HumanoidRootPart.Position)
v.Character:PivotTo(NewPivot)
end
end
print("Teleported players because "..Player.Name.." activated")
Connection:Disconnect()
end
end)
As it seems you originally wanted, judging by your use of :Once() this event will only fire one time
If you would like to change this functionality, remove the