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

Touched not working, what's the problem?

Asked by 4 years ago
Edited 4 years ago

What's wrong with my script? Only the first print statement is processed.

 function onTouched(hit)
    if script.CoolDown.Value == false then
        script.CoolDown.Value = true
        print("1")
            if hit.Name == "Engine" then
            print("2")
                if workspace.TrashcanLocation.Value == 0 then
                print("3")
                workspace.TrashcanLocation.Value = 1
                print("4")
            end
        end
        wait(1)
        script.CoolDown.Value = false
    end
end

script.Parent.Touched:connect(onTouched)

This server script is inside of a trigger. When a part named "Engine" touches the trigger, it changes a value to 1 if it was previously 0.

0
Use some print blocks to make sure it is getting past the if blocks. For example, put "print('part is named engine')" after the first if statement and "print('changing value to 1')" after the next if statement. That may help you figure out your problem sheepposu 561 — 4y
0
This is so weird. I added print statements all over the code and none of them are processed! The script isn't disabled, so I don't know what the problem is here! Casual_Keldeo 4 — 4y
0
For some reason, "1" is printed on the client, and then "1" and "2" are printed on the server. This is so frustrating!! Casual_Keldeo 4 — 4y
0
THE PLOT THICKENS! I added an elseif then print statement, and for some reason, the script refuses to believe that the value is 0! Casual_Keldeo 4 — 4y

Answer this question