hey, I need help with localscript, it is inside the player and I want the doors to slide open on keypress, for example. I am near to door1 and press f and it opens. basically which ever the player is nearest of the doors
can anyone help me out? please!!
function waitForChild(parent, childName) local child = parent:FindFirstChild(childName) if child then return child end while true do child = parent.ChildAdded:wait() if child.Name==childName then return child end end end local doornumber = { [game.Workspace.Door] = { distance = 3, Door = game.Workspace.Door, Part1 = game.Workspace.Door.Part1, Part2 = game.Workspace.Door.Part2, E1 = game.Workspace.Door.E1.E, E2 = game.Workspace.Door.E2.E }, [game.Workspace.Door1] = { distance = 3, Door = game.Workspace.Door1, Part1 = game.Workspace.Door1.Part1, Part2 = game.Workspace.Door1.Part2, E1 = game.Workspace.Door1.E1.E, E2 = game.Workspace.Door1.E2.E } } openspeed = 3 closespeed = -3 local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.KeyDown:connect(function(key) if key == "f" then for Door, props in pairs(doornumber) do if player.Character and (player.Character.Torso.Position - Door.Position).magnitude > props.distance then E2.Enabled = false ---- disables billboard E1.Enabled = false ---- disables billboard Part2.CFrame = Part2.CFrame + (Part2.CFrame.lookVector * openspeed) --- right door slides to the right Part1.CFrame = Part1.CFrame + (Part1.CFrame.lookVector * openspeed) -- left door slides to the left wait(3) --- below does opposite after 3 seconds E2.Enabled = true E1.Enabled = true Part2.CFrame = Part2.CFrame + (Part2.CFrame.lookVector * closespeed) Part1.CFrame = Part1.CFrame + (Part1.CFrame.lookVector * closespeed) end end end end)
So far at a glance i dont see anything wrong but this line But its just a glance so i may be wrong ;p
if player.Character and (player.Character.Torso.Position - Door.Position).magnitude > props.distance then
change that ">" sign to "<="
if player.Character and (player.Character.Torso.Position - Door.Position).magnitude <= props.distance then