local questNumber = workspace.Quest.QuestNumber function onTouched(hit) if questNumber.Value == 1 then questNumber.Value = 0 end end script.Parent.Touched:connect(onTouched)
I want to make a block that when you touch it, the script checks if the value is 1 and if the value is 1 the script sets this value to 0. Its really simple, but I DONT UNDERSTAND WHY MY SCRIPT UP THERE DONT WORK!! Pls can someone help me.
(sorry if my English is bad)
I would personally prefer to use Anonymous functions
Also the Touched event happens whenever the part is touched by any object you would have to make sure you add limitations to make sure that only a character can touch the part:
local questNumber = workspace.Quest.QuestNumber script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- make sure the touched object is a player if questNumber.Value == 1 then questNumber.Value = 0 end end end)
Is your code in a Script or a LocalScript?
Make sure it's in a Script, because with FilteringEnabled on, the LocalScript won't be able to set the value correctly.
Otherwise, is there any error message printing out?