Yes, it's definitely possible to create an NPC shop in Roblox without using a Humanoid. You can use a simple Part or a Model as the NPC and attach the ProximityPrompt to it. Here’s how you can set it up:
Steps to Create an NPC Shop Without a Humanoid
1. Create the NPC Model
- Insert a
Part or a Model into the workspace. This will act as your NPC.
- For example, insert a
Part and name it "NPC".
- (Optional) Customize the NPC by adding a
Mesh, Texture, or other details to make it look like a shopkeeper.
2. Add a ProximityPrompt to the NPC
- Select the NPC (
Part or Model).
- In the Explorer, right-click the NPC and insert a ProximityPrompt.
- Configure the
ProximityPrompt properties:
PromptText: "Press E to Open Shop"
Distance: 10 (or your preferred range)
ActionText: "E"
HoldDuration: 0 (or a small value if you want the player to hold the key)
3. Create the LocalScript
- Place a LocalScript in
StarterPlayerScripts or StarterGui to handle the shop GUI.
- Here’s the script:
-- LocalScript in StarterPlayerScripts or StarterGui
local npc = workspace:FindFirstChild("NPC") -- Replace "NPC" with your NPC's name
if not npc then
warn("NPC not found in workspace!")
return
end
local proximityPrompt = npc:FindFirstChild("ProximityPrompt")
if not proximityPrompt then
warn("ProximityPrompt not found on NPC!")
return
end
proximityPrompt.Triggered:Connect(function(player)
if player == game.Players.LocalPlayer then
openShopGui()
end
end)
local function openShopGui()
local shopGui = game.ReplicatedStorage:FindFirstChild("ShopGui")
if not shopGui then
warn("ShopGui not found in ReplicatedStorage!")
return
end
local guiClone = shopGui:Clone()
guiClone.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local mainFrame = guiClone:FindFirstChild("MainFrame")
if mainFrame then
mainFrame.Visible = true
else
warn("MainFrame not found in ShopGui!")
end
end
4. Store the ShopGui in ReplicatedStorage
- Ensure your
ShopGui is stored in ReplicatedStorage (as mentioned earlier).
5. (Optional) Add a Close Button
- If you want to add a close button to the shop GUI, follow the same steps as before. Add a
TextButton named "CloseButton" inside MainFrame and connect its MouseButton1Click event to destroy the GUI.
Example for the close button:
local closeBtn = mainFrame:FindFirstChild("CloseButton")
if closeBtn then
closeBtn.MouseButton1Click:Connect(function()
guiClone:Destroy()
end)
end
Full Example Code
-- LocalScript in StarterPlayerScripts
local npc = workspace:FindFirstChild("NPC") -- Replace "NPC" with your NPC's name
if not npc then
warn("NPC not found in workspace!")
return
end
local proximityPrompt = npc:FindFirstChild("ProximityPrompt")
if not proximityPrompt then
warn("ProximityPrompt not found on NPC!")
return
end
proximityPrompt.Triggered:Connect(function(player)
if player == game.Players.LocalPlayer then
openShopGui()
end
end)
local function openShopGui()
local shopGui = game.ReplicatedStorage:FindFirstChild("ShopGui")
if not shopGui then
warn("ShopGui not found in ReplicatedStorage!")
return
end
local guiClone = shopGui:Clone()
guiClone.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local mainFrame = guiClone:FindFirstChild("MainFrame")
if mainFrame then
mainFrame.Visible = true
-- Optional: Add close button functionality
local closeBtn = mainFrame:FindFirstChild("CloseButton")
if closeBtn then
closeBtn.MouseButton1Click:Connect(function()
guiClone:Destroy()
end)
end
else
warn("MainFrame not found in ShopGui!")
end
end
Key Points
- The NPC doesn’t need a
Humanoid—it can be a simple Part or Model.
- The
ProximityPrompt is attached directly to the NPC.
- The script finds the NPC in the workspace and listens for the
Triggered event.
- The shop GUI is cloned and parented to the player’s
PlayerGui when the prompt is triggered.
Let me know if you need further assistance!