and the problem is whenever I click a key, it is not deleting the item and going into my inventory.
KeyScript:
local module = {}
function module.DropTools(plr,map,position)
for i, tool in pairs(plr.Backpack:GetChildren()) do
if tool:IsA("Tool") and game.ServerStorage.KeyHandles:FindFirstChild(tool.Name) then
local clone = game.ServerStorage.KeyHandles:FindFirstChild(tool.Name):Clone()
if clone:IsA("Model") then
clone:SetPrimaryPartCFrame(CFrame.new(position))
else
clone.Position = position
end
clone.Parent = map.Items
tool:Destroy()
end
end
for i, tool in pairs(plr.Character:GetChildren()) do
if tool:IsA("Tool") and game.ServerStorage.KeyHandles:FindFirstChild(tool.Name) then
local clone = game.ServerStorage.KeyHandles:FindFirstChild(tool.Name):Clone()
if clone:IsA("Model") then
clone:SetPrimaryPartCFrame(CFrame.new(position))
else
clone.Position = position
end
clone.Parent = map.Items
tool:Destroy()
end
end
end
function module.Clicked(plr,item)
if plr then
if plr.Character and not plr:FindFirstChild("Piggy") then
local position
if item:IsA("Model") then
position = item.PrimaryPart.Position
else
position = item.position
end
module.DropTools(plr,game.Workspace.Map,position)
print("Droppped...KeyHandles")
if game.ServerStorage.Tools:FindFirstChild(item.Name) then
local clonedTool = game.ServerStorage.Tools[item.Name]:Clone()
clonedTool.Parent = plr.BackPack
plr.Character.Humanoid:EquipTool(clonedTool)
item:Destroy()
print("Equipped the new tool!")
end
end
end
end
return module
there are no errors on the output…
Video:
More Screenshots:
script Inside of the key models:
local keyModule = require(game.ServerScriptService:WaitForChild("Game Logic").KeyModule)
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
keyModule.Clicked(plr,script.Parent)
end)
Hope you can anwser me soon, if you want more information then just ask.
Thank you!
Not sure but perhaps showing the output when you actually clicked the key would be nice. Is anything getting printed? May I ask whats in “KeyHandles” folder.
I don’t see a reason why he shouldn’t make a piggy/granny game,
He want’s to learn. And I’m supporting him, saying “you shouldn’t make that game” is really discouraging and demotivative. There’s people that love the style of piggy games and he’s just asking a simple question, If you’re gonna be offensive just ignore this topic, Thank you.