cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 23 Jul 2014 11:39 PM |
Title says it all mostly... I have been searching for tutorials for ever and not one has explained how to make a door slide open when you click a key on the keyboard.
Does anyone have any suggestions on how this can be achieved?
I have created a script and put it in the Player Starter Pack... not quite sure if you need this to be able to press a key for an event to occur or not.
SCRIPT: Player = script.Parent.Parent mouse = Player:GetMouse()
function onKeyDown(key) key = key:lower()
if key == "e" then end
end |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 23 Jul 2014 11:41 PM |
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(k) if k == "e" then --open the door end end) |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 23 Jul 2014 11:44 PM |
| put nomer's code in a localscript wherever you want |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2014 11:44 PM |
No^
Only in the character, playergui or playerbackpack |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 23 Jul 2014 11:50 PM |
| Do I need to add a separate script in the sliding door itself to open when I get close to it and press the key "e"? |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 23 Jul 2014 11:54 PM |
| Oh by the way... play the game "Darkness" that is the type of door I am trying to create |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 24 Jul 2014 01:08 AM |
Alright this is the code I have came up with which I have put in the button that makes the door open:
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(k) if k == "e" then for i = 1,90 do wait() script.Parent.Parent.Door.CFrame = script.Parent.Parent.Door.CFrame * CFrame.new(0.1, 0, 0) * CFrame.fromEulerAnglesXYZ(0, 0, 0) end script.Value.Value = true script.Parent.Parent.BrickColor = BrickColor.new("Bright red") else for i = 1,90 do wait() script.Parent.Parent.Door.CFrame = script.Parent.Parent.Door.CFrame * CFrame.new(-0.1, 0, 0) * CFrame.fromEulerAnglesXYZ(0, 0, 0) end script.Value.Value = false script.Parent.Parent.BrickColor = BrickColor.new("Lime green")
end end )
A FEW PROBLEMS: - Slides to slowly - Pressing "e" doesn't open the door - Color of block doesn't change to red as I press it
Any suggestions? |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 24 Jul 2014 08:56 AM |
| How do you know it goes to slowly if it doesn't even go? |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 24 Jul 2014 12:04 PM |
@Kodran I made it open using a button which I click to open it and it opens way to slowly...
UPDATE: I have gotten one door to open using this code; however, when I make duplicates of the doors and try to open the duplicates they do not open. What am I doing wrong people?!?! This Local Script is in the players starter pack:
Permission = {"Xduel","Goulstem","Player1"} mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function(key) for i,v in pairs(Permission) do if v == game.Players.LocalPlayer.Name then distance = 10 --Wanted minimum distance from door here print("Press E To Open") if (game.Players.LocalPlayer.Character.Torso.Position - Workspace.SlidingDoor.Door.Position).magnitude <= distance then keyy = "e" if (key:lower()) == keyy then Workspace.SlidingDoor.Door.Transparency = .7 Workspace.SlidingDoor.Door.CanCollide = false wait(3) Workspace.SlidingDoor.Door.Transparency = 0 Workspace.SlidingDoor.Door.CanCollide = true end end end end end)
Could it be that I just need to put this script in every door I want to open when I get near it and press "e"? Please help people we almost got it! |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 24 Jul 2014 12:07 PM |
Oh, one other thing... I wanted it to say when you get close to the door "Press E To Open"
I tried to do this using this code (taken from the code above): print("Press E To Open")
This code does not work however....
So what am I doing wrong with all these things? |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2014 12:30 PM |
LocalScript. This is a ridiculously painful way to do it and this also took me fifteen minutes, but here. Put your doors in a model in Workspace named "Doors".
mouse=game.Players.LocalPlayer:GetMouse() function checkDoorDistance(torso,doors,dist) for i,v in pairs(doors) do if (v.Position-torso.Position).magnitude<=dist then return true end end end
function findNearestDoor(torso,doors) mags={} for i=1,#doors do table.insert(mags,#mags+1,(#doors[i].Position-torso.Position).magnitude) end return math.min(mags) end
while wait(0.5) do if checkDoorDistance(game.Players.LocalPLayer.Character.Torso ,Workspace.Doors:GetChildren()) then --create a gui, I'm too lazy end
mouse.KeyDown:connect(function(key) if key=="e" and checkDoorDistance() then door=findNearestDoor(game.Players.LocalPlayer.Character.Torso,Workspace.Doors:GetChildren()) --open door, (door is defined as door) I'm too lazy to write that end end)
|
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 24 Jul 2014 01:19 PM |
Ok so I have this script the Starter Pack with a model in the Workspace labeled "Doors" and inside this model there are four doors all labeled "Door". I tested it out but it won't work. Did I name the parts wrong?
mouse=game.Players.LocalPlayer:GetMouse() function checkDoorDistance(torso,doors,dist) for i,v in pairs(doors) do if (v.Position-torso.Position).magnitude<=dist then return true end end end
function findNearestDoor(torso,doors) mags={} for i=1,#doors do table.insert(mags,#mags+1,(#doors[i].Position-torso.Position).magnitude) end return math.min(mags) end
while wait(0.5) do if checkDoorDistance(game.Players.LocalPLayer.Character.Torso ,Workspace.Doors:GetChildren()) then --create a gui, I'm too lazy end
mouse.KeyDown:connect(function(key) if key=="e" and checkDoorDistance() then door=findNearestDoor(game.Players.LocalPlayer.Character.Torso,Workspace.Doors:GetChildren()) Workspace.Doors.Door.Transparency = .7 Workspace.Doors.Door.CanCollide = false wait(3) Workspace.Doors.Door.Transparency = 0 Workspace.Doors.Door.CanCollide = true end end) end |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 24 Jul 2014 01:25 PM |
If you reference the same door in every script, of course the same door will open every time!
What you should do is name all your doors differently, so you can refer to different ones in your script.
Or you can judge by distance, which I believe someone already provided an example for that
-I just hit 4k posts, made a lengthy speech lol: http://www.roblox.com/Forum/ShowPost.aspx?PostID=141338105- |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 24 Jul 2014 01:33 PM |
This script here works if I put each door in a model named SlidingDoor, SlidingDoor1, Etc... with a new Local Script for each door:
Permission = {"Xduel","Goulstem","Player1"} mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function(key) for i,v in pairs(Permission) do if v == game.Players.LocalPlayer.Name then distance = 10 --Wanted minimum distance from door here print("Press E To Open") if (game.Players.LocalPlayer.Character.Torso.Position - Workspace.SlidingDoor.Door.Position).magnitude <= distance then keyy = "e" if (key:lower()) == keyy then Workspace.SlidingDoor.Door.Transparency = .7 Workspace.SlidingDoor.Door.CanCollide = false wait(3) Workspace.SlidingDoor.Door.Transparency = 0 Workspace.SlidingDoor.Door.CanCollide = true end end end end end)
I need the "Permissions" to allow any player that plays my game to be allowed to open the door. Right now (as you can see) only "Xduel","Goulstem", and "Player1" have permission |
|
|
| Report Abuse |
|
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
| |
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
| |
|
cfiredog
|
  |
| Joined: 30 May 2008 |
| Total Posts: 228 |
|
|
| 25 Jul 2014 07:13 PM |
| Come on people I need help... |
|
|
| Report Abuse |
|
|