ClickDetector not working for pets to attack

Hello everyone,

I’ve stumbled onto a issue where once I click on a model with my pet equipped it does not attack on a ‘click’ input. I have my output tab opened up but no errors are showing up so I am lost now on the whole process!

I’m a beginner into the coding world so I’ve been just following videos to figure out problems and solutions.

Video that I’m following (Stuck on 19:56):

Video example of me clicking on the crate and no actions sequence takes place.

Image of the coding and workspace to show the process has been done as followed

Any guidance would greatly be appreciated, thank you! :see_no_evil:

Be sure the script is a child of the ClickDetector of course. Check if the ClickDetector is enabled too.

since when scripting support became YT tutorial support?
Be more respectful and better post please.
Follow template at least cmon bro it cant be so hard for you to do that.
Provide actual code and not just a screenshots.
You provide no information as what is not working/error screenshots

2 Likes

I do completely agree with you in fact, hm.

1 Like

First and foremost, I’ll be an adult in replying to this, I apologize for what ever seems to be irritating you from this post, as everything is a learning process for me and I’ll take this as a sort of criticism.

local Players = game:GetService("Players")

local MainFolder_Workspace = workspace.MainFolder_Workspace
local PlayerPets = MainFolder_Workspace.PlayerPets
local drops = MainFolder_Workspace.Drops

Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = player.Name
	folder.Parent = PlayerPets
	
	for _, v in pairs(script.PlayerData:GetChildren()) do
		v:Clone().Parent = player
	end
end)

Players.PlayerRemoving:Connect(function(player)
	if PlayerPets:FindFirstChild(player.Name) then
		PlayerPets:FindFirstChild(player.Name):Destroy()
	end
end)

for _, drop in pairs(drops:GetDescendants()) do
	if drop:IsA("Model") then
		drop.ClickDetector.MouseClick:Connect(function(player)
			local currentPlayerPets = PlayerPets[player.Name]
			if #currentPlayerPets:GetChildren() > 0 then
				local pet = currentPlayerPets:FindFirstChildOfClass("Model")
				if player.Values.SentTo.Value == nil then
					player.Values.SentTo.Value = drop
					pet.Attack.Value = player.Values.SentTo.Value
				elseif player.Values.SentTo.Value == drop then
					player.Values.SentTo.Value = nil
					pet.Attack.Value = player.Values.SentTo.Value
				elseif player.Values.SentTo.Value ~= nil and player.Values.SentTo.Value ~= drop then
					player.Values.SentTo.Value = drop
					pet.Attack.Value = player.Values.SentTo.Value
				end
			end
		end)
	end
end

Here is the coding block you mentioned, as for the problem I’m having if it was not understandable with the video and caption with it, the pet models are not attacking (going to) the drop (crate) upon clicking on the drop model. Furthermore, as for any errors this is where another problem lies, I don’t seem to be getting any error coding on the output so I can’t honestly tell where the problem is, that is why screenshots are sent!

The YT video sent up was to just track where I was trying to go with the project, as well as have a better understanding on where my problem lies, and if in anyway that is disrespectful towards the programming community, again I do apologize, I will do better to post.

Again, guidance would be greatly appreciated, thanks.

Yes, the ClickDetector was enabled and I had moved the script under the the ClickDetector but that didn’t seem to do anything.

The code you’ve sent seems fine. There’s nothing in it that has anything to do with the actual pet going to the drop and attacking it though. Could another script be the issue?