Trouble with my Server Side Script and No error message

I’ve gotten back into coding today after taking a couple of months off and I am really stumped at this, I don’t know what’s wrong with it, it doesn’t even have an error message

This is the Server Script Storage Script

local OpenDoorEvent = game.ReplicatedStorage.OpenDoor
local door = game.Workspace.Door

local function OpenDoor()
		door.CanCollide = false
		door.Transparency = 0.5
		wait(3)
		door.CanCollide = true
		door.Transparency = 0
	end

OpenDoorEvent.OnServerEvent:Connect(OpenDoor)
end)

This is the Local Script.

local OpenDoorEvent = game.ReplicatedStorage.OpenDoor

local function triggerevent()
		OpenDoorEvent:FireServer()
end

game.Workspace.Door.ClickDetector.MouseClick:Connect(triggerevent)

Remove the extra end)

local OpenDoorEvent = game.ReplicatedStorage.OpenDoor

local door = game.Workspace.Door

local function OpenDoor()

door.CanCollide = false

door.Transparency = 0.5

wait(3)

door.CanCollide = true

door.Transparency = 0

end

OpenDoorEvent.OnServerEvent:Connect(OpenDoor)

It still doesn’t work, but thank you for trying

Youre trying to connect a event inside a function, which means, the function would need to actively be run and that would again just open the door without the event being fired.
Heres something that might fix it:

local OpenDoorEvent = game.ReplicatedStorage.OpenDoor
local door = game.Workspace.Door

local function OpenDoor()
		door.CanCollide = false
		door.Transparency = 0.5
		wait(3)
		door.CanCollide = true
		door.Transparency = 0
end
OpenDoorEvent.OnServerEvent:Connect(OpenDoor)

You shouldnt put a connection to a event in a function since the function can only be run when called.

1 Like

If you’re just using a simple ClickDetector, you can just do everything server-sided (with a cooldown, might I add.)

local Door = script.Parent
local ClickDetector = Door.ClickDetector
local Cooldown = false


local function OnMouseClick(Player)
    if (Cooldown) then return end
    Cooldown = true
    
    Door.CanCollide = false
    Door.Transparency = 0.5
    task.wait(3)
    Door.CanCollide = true
    Door.Transparency = 0
    
    Cooldown = false
end


ClickDetector.MouseClick:Connect(OnMouseClick)

Oh, i saw the script a bit wrong, what you did there was trying to close a already closed function (in this case OpenDoorEvent.OnServerEvent:Connect(OpenDoor)).
You only need to close a function on a connection if you write the script inside the connection.

--example
RemoteEvent.OnServerEvent:Connect(function()
    print("Hello World!")
end)

If you already have the function, you dont need to close it.

--example
function OnEvent()
    print("Hello World!")
end
RemoteEvent.OnServerEvent:Connect(OnEvent)

So actually @spvcta was right so i don’t know if mine doesnt work also but his script should work too.