Hi, I’m trying to make a tycoon game but this script isn’t working, its supposed to destroy the part on contact with the part destroyer, can someone help me?
local CashValue = script.Parent.Parent.Parent.Parent.Values.CashValue
script.Parent.Touched:Connect(function(Hit)
if Hit.Name == "Part" and Hit:FindFirstChild("CashValue") then
CashValue.Value += Hit:FindFirstChild("CashValue").Value
Hit:Destroy()
end
end)
Could you explain a little more about how the script does not work? Have you run a print statement inside your if-statement to test out if the if-statement is true? This will not run if one of those conditions is false. You can check if one of those statements is false by printing the condition before the if-statement
Can you try printing all parts that are hitting the register? Let me know the output and I could possibly help you.
Also, make sure that CashValue is either an instance or is being used properly. This could cause breakage in your code resulting in it stopping the function. You can also try printing the CashValue and see what it does to find out if this is the case
local part = script.Parent
local cash = part:WaitForChild("CashValue")
local onlyOnce = true -- debounce
part.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") and onlyOnce == true then -- Confirm tthat humanoid entitty touched the part
onlyOnce = false
print(cash.Name, cash.Value) -- will print (CashValue, 50 or some value you put)
end
end)