I’m trying to make a door for an in-game shop. So, I am programming the door to make it open using tween service. I am an intermediate scripter, so I need some help with the script for the door.
The problem is that the door doesn’t do anything when I touch it, I also wanted the door to detect a player and it will open.
Here is the script I made for the door:
local ld = script.Parent
local rd = workspace.rIGHTDOOR.Union
local playerclose = 10
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1)
-- opening (issue snippet)
ld.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local torso = character:FindFirstChild("Torso")
if torso then
local distance = (torso.Position - ld.Position).Magnitude
if distance <= playerclose then
local goal = {Position = Vector3.new(20.25, 5.5, 10.5)}
local tween = tweenservice:Create(ld,tweeninfo,goal)
tween:Play()
wait(1)
local goal2 = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween2 = tweenservice:Create(rd,tweeninfo,goal2)
tween2:Play()
wait(1)
local goal3 = {Position = Vector3.new(20.25, 5.5, 10.5)}
local tween3 = tweenservice:Create(rd,tweeninfo,goal3)
tween3:Play()
wait(1)
local goal4 = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween4 = tweenservice:Create(ld,tweeninfo,goal4)
tween4:Play()
end
end
end
end
end)
-- closing
ld.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local torso = character:FindFirstChild("Torso")
if torso then
local distance = (torso.Position - ld.Position).Magnitude
if distance >= playerclose then
local goal = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween = tweenservice:Create(ld,tweeninfo,goal)
tween:Play()
end
end
end
end
end)
This is the video that shows the issue:
And these are the objects I used to make the door:
local ld = script.Parent
local rd = workspace.rIGHTDOOR.Union
local playerclose = 10
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1)
-- opening (issue snippet)
ld.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
local distance = (hrp.Position - ld.Position).Magnitude
if distance <= playerclose then
local goal = {Position = Vector3.new(20.25, 5.5, 10.5)}
local tween = tweenservice:Create(ld,tweeninfo,goal)
tween:Play()
wait(1)
local goal2 = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween2 = tweenservice:Create(rd,tweeninfo,goal2)
tween2:Play()
wait(1)
local goal3 = {Position = Vector3.new(20.25, 5.5, 10.5)}
local tween3 = tweenservice:Create(rd,tweeninfo,goal3)
tween3:Play()
wait(1)
local goal4 = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween4 = tweenservice:Create(ld,tweeninfo,goal4)
tween4:Play()
end
end
end
end
end)
local ld = script.Parent
local rd = workspace.rIGHTDOOR.Union
local playerclose = 10
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1)
-- opening (issue snippet)
ld.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
local distance = (hrp.Position - ld.Position).Magnitude
if distance <= playerclose then
local goal = {Position = Vector3.new(20.25, 5.5, 10.5)}
local tween = tweenservice:Create(ld,tweeninfo,goal)
tween:Play()
wait(1)
local goal2 = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween2 = tweenservice:Create(rd,tweeninfo,goal2)
tween2:Play()
wait(1)
local goal3 = {Position = Vector3.new(20.25, 5.5, 10.5)}
local tween3 = tweenservice:Create(rd,tweeninfo,goal3)
tween3:Play()
wait(1)
local goal4 = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween4 = tweenservice:Create(ld,tweeninfo,goal4)
tween4:Play()
end
end
end
end
end)
ld.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
local distance = (hrp.Position - ld.Position).Magnitude
if distance > playerclose then
local goal = {Position = Vector3.new(20.25, 5.5, 2.5)}
local tween = tweenservice:Create(ld,tweeninfo,goal)
tween:Play()
end
end
end
end
end)
I added a snippet to make it close, but there is something wrong in the action, and I’m not very good using TweenService.