✓ Accepted answer
##Problem:
The reason .TouchedEnded didn't work properly, was because of your debounce function.
Everything else is fine, except for your debounce.
##Information:
The error was caused because you checked to see if debounce was false in lines 5 -6, but you didn't actually put a wait in between the debounce, so essentially it would spam "shop activated" and debounce would have no use. It's also better to end the debounce in the function rather than outside the scope.
On line 16, you're checking to see if debounce is false, since you set debounce to true on line 7, that wouldn't run the code, because debounce isn't false.
##Fixed Script:
local db = false
game.Workspace.Shop.Shop.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and db == false then
db = true
wait(1)
print("shop activated")
db = false
end
end)
game.Workspace.Shop.Shop.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and db == false then
db = true
wait(1)
db = false
print("shop deactivated")
end
end)
OR:(You could do this, although, the above script is more efficient:)
local db = false
game.Workspace.Shop.Shop.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if db == false then
db = true
wait(1)
print("shop activated")
db = false
end
end
end)
game.Workspace.Shop.Shop.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if db == false then
db = true
wait(1)
print("shop deactivated")
db = false
end
end
end)
#####Any more edits are gonna be on the wording in the answer!
3 comments
I didn't quite understand what you meant by switching value comparison and assignment, do I just switch the true and false values in the code?
oh just in the touchended function
Yeah, sorry I should have made it clearer bro