I made a collecting script that makes the object destroy when it’s touched by a player. No part of the script is working, not even the prints.

In the ElixirDropCollect script
print("yo")
local elixir = script.Parent
local currency = "Elixir"
local amt = 1
print("hi")
local d = true
elixir.Touched:Connect(function(p)
print("hello")
if p.Parent:FindFirstChild("Humanoid") and d then
d = false
local plr = game.Players:FindFirstChild(p.Parent.Name)
plr:FindFirstChild("leaderstats"):FindFirstChild(currency).Value = plr:FindFirstChild("leaderstats"):FindFirstChild(currency).Value + amt
elixir:Destroy()
end
end)
try placing the script into a local script
iam on phone too, well my computer is broken
LocalScript won’t help us in this case. I think that something is broken when detecting that player have touched a part.
1 Like
Ok here is the code that I wrote:
local amt = 1
function OnTouch(part)
if (part.Parent:FindFirstChild("Humanoid") ~= nil) and then
local p = game.Players:GetPlayerFromCharacter(part.Parent)
if (p ~= nil) then
local leaderstats = p:WaitForChild("leaderstats")
local elixir= leaderstats:WaitForChild("Elixir")
elixir.Value = elixir.Value + amt
script.Parent:Destroy()
end
end
end
script.Parent.Touched:connect(OnTouch)
I hope that I helped. mark this as a
Solution!