Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
Never
local userInputService = game:GetService("UserInputService")
local remoteEvent = game.ReplicatedStorage.WardrobeModelEntranceEvent
local remoteEventt = game.ReplicatedStorage.WardrobeMovingPart
local waiting = false
local playerInside = false

local function checkInput(input)
	if input.KeyCode == Enum.KeyCode.Space then
		remoteEvent:FireServer("EnterModel")
		if playerInside == true then
			remoteEvent:FireServer("ExitModel")
		end
	end
end	

userInputService.InputBegan:Connect(checkInput)


remoteEvent.OnClientEvent:Connect(function(action, data)
	if action == "Occupied" then
		print("The model is already occupied by", data.Name)
	elseif action == "PlayerInside" then
		local previousPlayerInside = playerInside
		playerInside = data

		if playerInside and not previousPlayerInside then
			print("Player entered the model!")
		end

		-- Handle the change in playerInside value as needed
		print("Player inside model:", playerInside)
	end
end)

local function checkInputt(input)
	if input.KeyCode == Enum.KeyCode.Left and waiting == false and playerInside == true then
		remoteEventt:FireServer("Movement")
		print("Pressed")
		waiting = true
		wait(5)
		waiting = false
	end
end

userInputService.InputBegan:Connect(checkInputt)