Error with detecting player

So I’m trying to make a door that slowly opens when someone touches an invisible part,idk how to make one but here’s what I made so far

local Left = script.Parent.LeftDoor
local Touch = script.Parent.Touch
local Right = script.Parent.RightDoor
local Player = game:GetService("Players"):GetPlayers()
local Target = Player:FindFirstChild("Torso")
local touches = game.GetService():Touches()

if Target.

Left.Position = Vector3.new(178, 21.326, -188.446)

Right.Position = Vector3.new(156, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(179, 21.326, -188.446)

Right.Position = Vector3.new(155, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(180, 21.326, -188.446)

Right.Position = Vector3.new(154, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(181, 21.326, -188.446)

Right.Position = Vector3.new(153, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(182, 21.326, -188.446)

Right.Position = Vector3.new(152, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(183, 21.326, -188.446)

Right.Position = Vector3.new(151, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(184, 21.326, -188.446)

Right.Position = Vector3.new(150, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(185, 21.326, -188.446)

Right.Position = Vector3.new(149, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(186, 21.326, -188.446)

Right.Position = Vector3.new(148, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(187, 21.326, -188.446)

Right.Position = Vector3.new(147, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(188, 21.326, -188.446)

Right.Position = Vector3.new(146, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(189, 21.326, -188.446)

Right.Position = Vector3.new(145, 21.326, -188.461)

wait(0.1)

Left.Position = Vector3.new(189, 21.326, -188.446)

Right.Position = Vector3.new(145, 21.326, -188.461)

This is a very impractical method, you should look into using TweenService. With this you can animate objects smoothly.

AlvinBlox made a great tutorial about it, he explains most of what you need to know for it.

1 Like

Also this if statement is not complete, change it up to this:

if Target then
   -- Tween Code
end

This variable should be removed too, it it’s useless and creates errors.
local touches = game.GetService():Touches()

Also, you have to use touched to detect when the player touches the part.
I am in a hurry so I can’t help more, tell me if you have questions.

1 Like

what I need mainly is detecting the player,I know about tween and the above script is just for reference for now

In order to detect when a player’s Character touches a part, the Touched event listener of a BasePart can be connected to a function.

When the event is fired and activates a given function, the data that is passed into the function is the Instance that touched the part and not the player Instance. This means that we’ll need to reference the parent of the Instance that Touched the part in order to access the player’s Character, and from there, the GetPlayerFromCharacter method can be utilized on the Character to accurately determine if it’s a player’s Character.

Example:

local Players = game:GetService("Players")

local part = script.Parent

part.Touched:Connect(function(object) -- "object" will reference the Instance that touched the part

    local player = Players:GetPlayerFromCharacter(object.Parent) -- Checks if a player Instance can be accessed from the Parent of the "object", which could be a player's Character model

    if player then -- If a player Instance was found, then object.Parent is the player's Character
        -- Continue
    end
end)

In order to move the door, the TweenService could be utilized, however, since multiple parts are being moved, I would suggest referencing the following guide for more information in regards to reliably achieving this:


Resources


Documentation

Touched Event Documentation

GetPlayerFromCharacter Documentation


Articles

Developer Onboarding

Code Fundamentals Series

Events Article

Functions Article

1 Like

After inserting the script the detection part disappears whenever testing