Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
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

Log in to vote
3
Answered by
Arkrei 389 Moderation Voter
5 years ago

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)

1
THX that work!! Man, you save me scorpion981 27 — 5y
1
Make sure you accept the answer to save peoples time and mark the question as answered Arkrei 389 — 5y
1
i dont know how scorpion981 27 — 5y
1
oh usually you hover over the answer Arkrei 389 — 5y
View all comments (4 more)
0
and a button would show up Arkrei 389 — 5y
0
i dont see it, i think my rep is too low scorpion981 27 — 5y
0
You don't need rep to accept an answer, its okay though people should see the question has been answered Arkrei 389 — 5y
0
ok scorpion981 27 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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?

0
Nothing in the outpout, and its a normal script scorpion981 27 — 5y
0
Then I would try reworking how you construct the script. See @Arkrei's answer for a better version. BreadyToCrumble 121 — 5y
0
Thx to you too! but Arkrei solve the problem. scorpion981 27 — 5y

Answer this question