Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When you touch the block the script checks if the value is 1 and then set it to 0?

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)

2 answers

✓ Accepted answer

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)

8 comments

1

THX that work!! Man, you save me

1

Make sure you accept the answer to save peoples time and mark the question as answered

1

i dont know how

1

oh usually you hover over the answer

0

and a button would show up

0

i dont see it, i think my rep is too low

0

You don't need rep to accept an answer, its okay though people should see the question has been answered

0

ok

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?

3 comments

0

Nothing in the outpout, and its a normal script

0

Then I would try reworking how you construct the script. See @Arkrei's answer for a better version.

0

Thx to you too! but Arkrei solve the problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.