Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Roblox Door Script only effects one player

Gotauia

New Coder
I've been trying to make a door open and close, simple, yet I've only got a week's worth of experience with this coding thing, so I'd like some help.

My code works, but it only works for one player, I would like if the code would open the door for all players in the server, could anyone help me with this? here is what I currently have


print(game.Players.LocalPlayer)

local door = game.Workspace.Door.Door

local Player = game.Players.LocalPlayer

local NearDoor = false

local RunService = game:GetService("RunService")

local status = "closed"







RunService.RenderStepped:Connect (function()

if Player😀istanceFromCharacter(game.Workspace.Door.Door.Position) < 10 then

NearDoor = true

game.Workspace.Door.E.Enabled = true

else

NearDoor = false

game.Workspace.Door.E.Enabled = false

end

end)





game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)



if key == "e" and NearDoor == true and status == "open" then

door.Rotation = Vector3.new(0, 0, 0)

door.Position = Vector3.new(14.5, 6.5, 17.5)

status = "closed"





elseif key == "e" and NearDoor == true and status == "closed" then

door.Rotation = Vector3.new(0, 100, 0)

door.Position = Vector3.new(17.2, 6.5, 20)

status = "open"







end

end)
 
For starters you should post your code inside the code blocks here so we can read it and actually be able to help you. 😀

View attachment 806
oh sorry, this is my first post, like this?
Code:
print(game.Players.LocalPlayer)
local door = game.Workspace.Door.Door
local Player = game.Players.LocalPlayer
local NearDoor = false
local RunService = game:GetService("RunService")
local status = "closed"



RunService.RenderStepped:Connect (function()
    if Player:DistanceFromCharacter(game.Workspace.Door.Door.Position) < 10 then
        NearDoor = true
        game.Workspace.Door.E.Enabled = true
    else
        NearDoor = false
        game.Workspace.Door.E.Enabled = false
    end
end)


game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)

    if key == "e" and NearDoor == true and status == "open" then
        door.Rotation = Vector3.new(0, 0, 0)
        door.Position = Vector3.new(14.5, 6.5, 17.5)
        status = "closed"

        
    elseif key == "e" and NearDoor == true and status == "closed" then
        door.Rotation = Vector3.new(0, 100, 0)
        door.Position = Vector3.new(17.2, 6.5, 20)
        status = "open"

        

    end
end)
 
Definitely better. I don't know the programming language so I won't be helpful syntax wise, but generally when you are looking to expand code that works in a single instances to work repeatedley you want to think in terms of loops.
 
oh sorry, this is my first post, like this?
Code:
print(game.Players.LocalPlayer)
local door = game.Workspace.Door.Door
local Player = game.Players.LocalPlayer
local NearDoor = false
local RunService = game:GetService("RunService")
local status = "closed"



RunService.RenderStepped:Connect (function()
    if Player:DistanceFromCharacter(game.Workspace.Door.Door.Position) < 10 then
        NearDoor = true
        game.Workspace.Door.E.Enabled = true
    else
        NearDoor = false
        game.Workspace.Door.E.Enabled = false
    end
end)


game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)

    if key == "e" and NearDoor == true and status == "open" then
        door.Rotation = Vector3.new(0, 0, 0)
        door.Position = Vector3.new(14.5, 6.5, 17.5)
        status = "closed"

       
    elseif key == "e" and NearDoor == true and status == "closed" then
        door.Rotation = Vector3.new(0, 100, 0)
        door.Position = Vector3.new(17.2, 6.5, 20)
        status = "open"

       

    end
end)
i should prob add this is in a localscript, its prob why it doesn't work server wide, but i have no idea how to rewrite this in script
 
I don't know the programming language
@Mangini, Roblox uses a modified version of the Lua scripting-language(version 5.1 or 5.2, I believe).

@Gotauia, it's been a long time since I did any Roblox stuff, however, I can tell you for starters that to make a door open/close for everyone, it cannot go into a localscript - this will only affect the local client and not the server client. It is possible to make a door open for everyone on the server, but since you are using RunService.RenderStepped, you are actually restricted to putting this code into a localscript(source: https://developer.roblox.com/en-us/api-reference/event/RunService/RenderStepped). Try putting it into a localscript anyway and if that doesn't work, come back.

Also, comments(which are denoted by -- or --[[ ]]-- in Lua) would be useful, because it then helps to understand the code better.
 
I've been trying to make a door open and close, simple, yet I've only got a week's worth of experience with this coding thing, so I'd like some help.

My code works, but it only works for one player, I would like if the code would open the door for all players in the server, could anyone help me with this? here is what I currently have


print(game.Players.LocalPlayer)

local door = game.Workspace.Door.Door

local Player = game.Players.LocalPlayer

local NearDoor = false

local RunService = game:GetService("RunService")

local status = "closed"







RunService.RenderStepped:Connect (function()

if Player😀istanceFromCharacter(game.Workspace.Door.Door.Position) < 10 then

NearDoor = true

game.Workspace.Door.E.Enabled = true

else

NearDoor = false

game.Workspace.Door.E.Enabled = false

end

end)





game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)



if key == "e" and NearDoor == true and status == "open" then

door.Rotation = Vector3.new(0, 0, 0)

door.Position = Vector3.new(14.5, 6.5, 17.5)

status = "closed"





elseif key == "e" and NearDoor == true and status == "closed" then

door.Rotation = Vector3.new(0, 100, 0)

door.Position = Vector3.new(17.2, 6.5, 20)

status = "open"







end

end)
Here's what happens:

You are using a local script, and what that does is that it the changes made are only on the client. The reasons why Roblox implemented this was because Exploiters (Or really just 'hackers') abused local-scripts low security to ruin players Experiences, and Roblox Added **Filtering Enabled** To Stop that.


What filtering enabled does is that local scripts changes only happen on your client and will never, ever replicate to the server.


However, you can use Remote Events to make the door changes. What it does is that it is a communication-path between Server And Client, where Server Goes to Client & Vice-Versa.

You can replicate this with:

Code:
<Remote Event>:FireServer(args)

That is on a local script, now here goes the server script:

Code:
<Remote Event>.OnServerEvent:Connect(function(player, args))
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom