-- Server Script inside TriggerPart and part2 local Players = game:GetService("Players")…
- User
-- Server Script inside TriggerPart and part2 local Players = game:GetService("Players") local ServerStorage = game:GetService("ServerStorage") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService")
local NPC = ServerStorage:FindFirstChild("npc") local StartShakeEvent = ReplicatedStorage:WaitForChild("StartShakeEvent") local StopShakeEvent = ReplicatedStorage:WaitForChild("StopShakeEvent") local UnlockEvent = ReplicatedStorage:WaitForChild("UnlockEvent") -- New RemoteEvent
-- Function to handle "TriggerPart" touch local function handleTriggerPartTouch(hit) local character = hit.Parent local player = Players:GetPlayerFromCharacter(character) if player then -- Prevent multiple triggers hit.Parent:FindFirstChild("TriggerPart"):Destroy()
code-- Summon NPC local npcClone = NPC:Clone() npcClone.Parent = workspace -- Position NPC at spawn location local npcSpawn = workspace:FindFirstChild("NPCSpawnLocation") if npcSpawn then npcClone:MoveTo(npcSpawn.Position) else warn("NPCSpawnLocation not found in Workspace.") end -- Notify client to start screen shake StartShakeEvent:FireClient(player) -- NPC chase logic local humanoid = npcClone:WaitForChild("Humanoid") local humanoidRootPart = npcClone:WaitForChild("HumanoidRootPart") local function chasePlayer() if npcClone and npcClone.Parent and character and character.Parent then humanoid:MoveTo(character.HumanoidRootPart.Position) end end local chaseConnection chaseConnection = RunService.Stepped:Connect(function() chasePlayer() end) -- Detect when NPC touches the player local touchedConnection touchedConnection = npcClone.HumanoidRootPart.Touched:Connect(function(otherPart) if otherPart:IsDescendantOf(character) then print("GAME OVER") -- Clean up if npcClone then npcClone:Destroy() end StopShakeEvent:FireClient(player) chaseConnection:Disconnect() touchedConnection:Disconnect() end end) -- Monitor if player is hiding local hidingCheckConnection hidingCheckConnection = RunService.Heartbeat:Connect(function() if character and character.Parent then local isHiding = false for _, part in ipairs(character:GetDescendants()) do if part:IsA("BasePart") then local touchingParts = part:GetTouchingParts() for _, touchedPart in ipairs(touchingParts) do if touchedPart.Name == "hide" then isHiding = true break end end end if isHiding then break end end if isHiding then -- Player is hiding if npcClone then npcClone:Destroy() end StopShakeEvent:FireClient(player) -- Clean up chaseConnection:Disconnect() touchedConnection:Disconnect() hidingCheckConnection:Disconnect() end else -- Player character removed hidingCheckConnection:Disconnect() end end) end - Assistant