Okay, so I know that there how been a ton of topics like this, but I’m sure mine is different.
I am trying to make an E to open door, it works fine, but I want to make it so that you can copy and paste it without having to change the code.
This is what I have tried:
Local script:
local RunService = game:GetService("RunService")
local CharacterNearDoor = false
local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
RunService.RenderStepped:Connect(function()
for i, v in pairs(game.Workspace.Doors:GetChildren()) do
if Player:DistanceFromCharacter(v.Door.Position) < 10 then
CharacterNearDoor = true
v.Door.DoorGui.Enabled = true
DoorWhichPlayerIsNear = v.Name
else
CharacterNearDoor = false
v.Door.DoorGui.Enabled = false
DoorWhichPlayerIsNear = nil
end
end
end)
UIS.InputBegan:Connect(function(Input, gameProccesedEvent)
if Input.KeyCode == Enum.KeyCode.E and CharacterNearDoor == true then
game.ReplicatedStorage.DoorOpenClose:FireServer(DoorWhichPlayerIsNear)
end
end)
ServerScript inside of each door:
--Dont worry about the opening and closing code.
local DoorOpen = false
local DoorName = script.Parent.Parent.Name
local LeftDoor = script.Parent.Parent.LeftDoor
local LeftDoorOpen = script.Parent.Parent.LeftDoorOpen
local RightDoor = script.Parent.Parent.RightDoor
local RightDoorOpen = script.Parent.Parent.RightDoorOpen
local RightDoorMetalPos = RightDoor.Metal.CFrame
local RightDoorWoodPos = RightDoor.Wood.CFrame
local LeftDoorWoodPos = LeftDoor.Wood.CFrame
local LeftDoorMetalPos = LeftDoor.Metal.CFrame
game.ReplicatedStorage.DoorOpenClose.OnServerEvent:Connect(function(player, DoorWhichPlayerIsNear)
warn(DoorWhichPlayerIsNear)
print(script.Parent.Parent.Name)
if DoorWhichPlayerIsNear == DoorName then
if DoorOpen == false then
DoorOpen = true
LeftDoor.Wood.CFrame = LeftDoorOpen.Wood.CFrame
LeftDoor.Metal.CFrame = LeftDoorOpen.Metal.CFrame
RightDoor.Wood.CFrame = RightDoorOpen.Wood.CFrame
RightDoor.Metal.CFrame = RightDoorOpen.Metal.CFrame
elseif DoorOpen == true then
DoorOpen = false
LeftDoor.Wood.CFrame = LeftDoorWoodPos
LeftDoor.Metal.CFrame = LeftDoorMetalPos
RightDoor.Wood.CFrame = RightDoorWoodPos
RightDoor.Metal.CFrame = RightDoorMetalPos
end
end
end)
I dont get any errors, but this weird thing happens:
So i have 3 doors, that print statement that prints the name of the door that the script is inside of prints this:
I have no idea why this happens.
Thank you for reading.