Hello Everybody,
I have a script that senses if a player clicks the bag of gold if he does then a function will run and lots of other things will happen. The issue when I click the click detector literally nothing happens. The script was working before now for reason it just completely shut down.
Here is a video of me trying to click the bag of gold. The click detector will just not work. NO ERRORS IN OUTPUT

server script
local CD = script.Parent -- click detector
local Hitbox = script.Parent.Parent
local Health = Hitbox.Parent.Health
local healthDisplay = Health.Parent.HealthDisplayPart.HealthDisplay
local CoinSound = game.Workspace["Coin Collect - SFX"]
local Explosion = Hitbox.Parent.Explosion
local CoreEmitter = Explosion.CoreEmitter
game.Players.PlayerAdded:Connect(function(plr)
local function DetectClick(playerWhoClicked)
-- CD function
local amountequuippedvalue = plr.PlayerGui.Inventory.LowerInvFrame.AmountEquipped.AmountEquippedValue-- value used to track the specified amount of pets equipped
local character = playerWhoClicked.Character:GetChildren() or playerWhoClicked.CharacterAdded:Wait():GetChildren()-- getting char
for _,pet in pairs(character) do
if pet ~= nil then
if pet:IsA("Model") then
-- if can a print, it will print the pet name ex:Dragon
print("Pet Found")
pet:PivotTo(Hitbox.CFrame)
local alignPosition = pet:WaitForChild("AlignPosition") or Hitbox:WaitForChild("AlignPosition")
local alignOrientation = pet:WaitForChild("AlignOrientation") or Hitbox:WaitForChild("AlignOrientation")
local attachmentpet = pet.PetHitBox:WaitForChild("Attachment")
local atttachmentTarget = Hitbox.Attachment
-- all these attachments and constrainst were created before hand
attachmentpet.Parent = pet.PrimaryPart
alignPosition.Attachment0 = attachmentpet
alignPosition.Attachment1 = atttachmentTarget
alignPosition.Parent = Hitbox
-- for positioning the pet
alignOrientation.Attachment0 = attachmentpet
alignOrientation.Attachment1 = atttachmentTarget
alignOrientation.Parent = Hitbox
-- for rotating the pet
if amountequuippedvalue.Value == 1 then
atttachmentTarget.Position = Vector3.new(0,0,4)
elseif amountequuippedvalue.Value == 2 then
atttachmentTarget.Position = Vector3.new(6,0,0)
atttachmentTarget.Orientation = Vector3.new(0,87,0)
elseif amountequuippedvalue.Value == 3 then
atttachmentTarget.Orientation = Vector3.new(0,185,0)
atttachmentTarget.Position = Vector3.new(0,0,-4)
elseif amountequuippedvalue.Value == 4 then
atttachmentTarget.Position = Vector3.new(-5,0,0)
atttachmentTarget.Orientation = Vector3.new(0,-90,0)
elseif amountequuippedvalue.Value == 5 then
atttachmentTarget.Position = Vector3.new(0,0,3)
-- tells the script where to postion the pet depending on the amount of pets Equipped
end
local function petAnimation()
local atttachmentTarget = Hitbox.Attachment -- attaching the pet to the target
while Health.Value >= 0 do
wait(1.5)
pet.PrimaryPart.CFrame = pet.PrimaryPart.CFrame + pet.PrimaryPart.CFrame.LookVector * 2
wait(1.5)-- pet animation where pet moves forward then repositions backworrds
pet.PrimaryPart.CFrame = pet.PrimaryPart.CFrame + pet.PrimaryPart.CFrame.LookVector * -1.5
healthDisplay.MaxDistance = 25
local DamageAmount = pet:WaitForChild("dmg")-- figure how to find the amount of the damage a pet does
Health.Value = Health.Value - DamageAmount.Value-- lessening the hp of the target
CoinSound:Play()-- playing a sound
print(DamageAmount.Value)
print(Health.Value)
local CoinsPopUpFrame = plr.PlayerGui.CurrencyUI.CoinPopUp
local Coin = CoinsPopUpFrame.ImageLabel:Clone()
CoinsPopUpFrame.Visible = true
Coin.ImageTransparency = 0
local xR = math.random(0,1000)
local yR = math.random(0,700)
Coin.Position = UDim2.new(0,xR,0,yR)
-- UI effects
Coin.Parent = CoinsPopUpFrame
local function callback()-- call back functions runs when tween is finished
print("Success")
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + math.random(1,5)
end
Coin:TweenSizeAndPosition(UDim2.new(0,0,0,0), UDim2.new(2,0,-2,0),Enum.EasingDirection.In, Enum.EasingStyle.Quart,5,true,callback)
-- getting rid of coins
if Health.Value <= 0 then
Health.Value = 0
CoreEmitter.Enabled = true
CoreEmitter.Transparency = NumberSequence.new(0,0.01)
local maxhp = 100
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + maxhp/4 or 5
-- giving the player a reward or gift, basically extra coins for destroying the target
-- Effects
local regularEmitters = {}
for _, child in ipairs(Explosion:GetChildren()) do
if child.Name ~= "CoreEmitter" then
table.insert(regularEmitters, child)
end
end
--particle effects
local randomEmitter = regularEmitters[math.random(1, #regularEmitters)]
print(randomEmitter)
randomEmitter.Enabled = true
randomEmitter.Transparency = NumberSequence.new(0,0.01)
-- more particle effects
local char = plr.Character
local humroot = char.HumanoidRootPart
local attachmentchar = humroot.Attachment
-- attachment used to position the pet as it was positon in the first place
print(attachmentchar)
alignPosition.Parent = pet
alignPosition.Attachment0 = attachmentpet
alignPosition.Attachment1 = attachmentchar
-- attaching the pet to the char and the char to pet
alignOrientation.Parent = pet
alignOrientation.Attachment0 = attachmentpet
alignOrientation.Attachment1 = attachmentchar
-- attaching the pet to the char and the char to pet
wait(2.5)
CD.Parent.Parent:Destroy() -- destroy the bag
end
end
end
petAnimation()
end
else
print("There was a issue with the pet loading")
end
end
--search char for Groups
--remote event
-- pet in LOCAL SCRIPT transfers to SERVER SCRIPT(So everybody can see the pet attacks and animations, and for the player to get the coins )
--------------------------------
-- remote event code
-- step1: make pet pivot to chest, then make animations while damage is being done, and do if damage then coins pop and SFX tho and leaderstats
end
CD.MouseClick:Connect(DetectClick)
end)

