Untitled
unknown
plain_text
2 years ago
3.2 kB
4
Indexable
local entrancePart = game.Workspace.WardrobeModel.Wardrobe
local door = game.Workspace.WardrobeModel.Door
local fearpartsfolder = game.Workspace.FearParts
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "WardrobeModelEntranceEvent"
remoteEvent.Parent = game.ReplicatedStorage
local remoteEventt = Instance.new("RemoteEvent")
remoteEventt.Name = "WardrobeMovingPart"
remoteEventt.Parent = game.ReplicatedStorage
local occupiedPlayer = nil
local isPlayerInside = false
local function enterModel(player)
if occupiedPlayer == nil then
-- Execute actions for entering the model
print("Player", player.Name, "entered the model.")
occupiedPlayer = player
isPlayerInside = true
remoteEvent:FireClient(player, "PlayerInside", isPlayerInside)
local characterr = player.Character or player.CharacterAdded:Wait()
for i, character in ipairs(characterr:GetDescendants()) do
if (character:IsA("BasePart") or character:IsA("Decal")) and character.Name ~= "HumanoidRootPart" then
character.Transparency = 1
else if character.Name == "Humanoid" then
character.WalkSpeed = 0
end
end
end
else
-- Print a message if the model is already occupied
print("The model is already occupied by", occupiedPlayer.Name)
remoteEvent:FireClient(player, "Occupied", occupiedPlayer)
end
end
local function exitModel(player)
if occupiedPlayer == player then
-- Execute actions for exiting the model
print("Player", player.Name, "exited the model.")
occupiedPlayer = nil
isPlayerInside = false
remoteEvent:FireClient(player, "PlayerInside", isPlayerInside)
local characterr = player.Character or player.CharacterAdded:Wait()
for i, character in ipairs(characterr:GetDescendants()) do
if (character:IsA("BasePart") or character:IsA("Decal")) and character.Name ~= "HumanoidRootPart" then
character.Transparency = 0.7
else if character.Name == "Humanoid" then
character.WalkSpeed = 16
end
end
end
end
end
remoteEvent.OnServerEvent:Connect(function(player, action)
if action == "EnterModel" then
local character = player.Character
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local rootPartTouch = humanoidRootPart:GetTouchingParts()
if rootPartTouch then
for _, part in ipairs(rootPartTouch) do
if part == entrancePart then
enterModel(player)
end
break
end
end
end
end
elseif action == "ExitModel" then
if occupiedPlayer == player then
exitModel(player)
end
end
end)
local function moveModel(player)
door.Transparency = 1
local part = Instance.new("Part")
part.Parent = fearpartsfolder
part.Name = "FearPart"
part.CanCollide = false
part.Anchored = true
part.Transparency = 0
part.Position = door.Position
part.BrickColor = BrickColor.new(27, 42, 53)
part.Size = door.Size
wait(5)
door.Transparency = 0
part:Destroy()
end
remoteEventt.OnServerEvent:Connect(function(player, action)
if action == "Movement" and occupiedPlayer == player then
moveModel()
end
end)Editor is loading...