Improvements
You made a local variable for the door but didnt use it
Connect should be used instead of connect [Deprecation]
Issues
Local Functions should be defined before they are called, not after
You did not bind the KeyCard connection with an event
The player's backpack contains the tool the player uses not the StarterPack
Information
Below I've used a RemoteEvent to allow the player's activation of the tool to affect the server
Added a debounce to prevent spam
Additional Local Script (under the Tool "KeyCard")
local keycard = script.Parent
local remote = game:GetService("ReplicatedStorage"):WaitForChild("KeyCardEvent")
keycard.Activated:Connect(function()
remote:FireServer()
end)
Revised Server Script (under the Part "Door")
local door = script.Parent
local debounce = false
local remote = Instance.new("RemoteEvent")
remote.Name = "KeyCardEvent"
remote.Parent = game:GetService("ReplicatedStorage")
local function DoorOpen()
door.Transparency = 0.5
door.CanCollide = false
end
local function DoorClose()
door.Transparency = 0
door.CanCollide = true
end
remote.OnServerEvent:Connect(function(player)
if debounce == false then
debounce = true
DoorOpen()
wait(1.5)
DoorClose()
wait(1.5)
debounce = false
end
end)
1 comment
hmm, good for one door.. i think I'd use ray to see what door is close by and the player is facing and then if the distance is short enough, allow the keycard to work - maybe if its close to the keycard/ fab reader.