local module = {}
local Workspace = game.GetService("Workspace")
local Drops = Workspace.Drops
local Pets = Workspace.Pets
function module.SendPet(Player, Drop)
if Player.Values.SentTo ~= Drop then
local PlayerPets = Pets:FindFirstChild(Player.Name)
if #PlayerPets:GetChildren() >= 1 then
local Pet = PlayerPets:GetChildren()[1]
Pet.PrimaryPart.AlignPosition.Attatchment1 = Drop.PrimaryPart.Attatchment
Pet.PrimaryPart.AlignOrientation.Attatchment1 = Drop.PrimaryPart.Attatchment
Player.Values.SentTo.Value = Drop
end
else
local PlayerPets = Pets:FindFirstChild(Player.Name)
if #PlayerPets:GetChildren() >= 1 then
local Pet = PlayerPets:GetChildren()[1]
Pet.PrimaryPart.AlignPosition.Attatchment1 = Player.Character.HumanoidRootPart.Attatchment1
Pet.PrimaryPart.AlignOrientation.Attatchment1 = Player.Character.HumanoidRootPart.Attatchment1
Player.Values.SentTo.Value = nil
end
end
end
function module.Setup()
for _, Drop in pairs(Drops:GetChildren()) do
local CD = Instance.new("ClickDetector")
CD.MaxActivationDistance = 15
CD.Parent = Drop
CD.MouseClick:Connect(function(Player)
module.SendPet(Player, Drop)
end)
end
end
return module
Do you have any errors? What is the script supposed to do? What does it actually do?
Help me help you! if you can answer all of the above I will know what I’m looking for.
i don’t have errors this script should actually let me click on a coin and have a click detector so my pet goes to the coin but i don’t get a clickdetector
Are you adding objects to Workspace.Drops after module.Setup is run?
no there are already 3 models in the drops(folder)
Are you requiring this module script somewhere? You should actually get an error on the first line, game:GetService requires a colon, not a dot. Otherwise your setup function works on my baseplate test place.
local my_module = require(path_to_your_module_script)
my_module.Setup()
do i need to put that cod somewhere in my code
It might be better to convert your module script into a Server or Local Script.
You can read more about module scripts and how to use them here ModuleScripts
function module.Setup()
for _, Drop in pairs(Drops:GetChildren()) do
local CD = Instance.new("ClickDetector")
CD.MaxActivationDistance = 15
CD.Parent = Drop
CD.MouseClick:Connect(function(Player)
module.SendPet(Player, Drop)
end)
end
end
i think this part is wrong because there will be no clickdetector in the coin model