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

Value changing when player touches a part system only working one time ?

Asked by 3 years ago

I want to make a system where if a player touches a specific part, then a value in it would change to true if not already, i have this script in the part :

local part = script.Parent
part.Touched:Connect(function(hit)
    print("Touched")
    if hit then
        if hit.Parent:FindFirstChild("Humanoid") then
            print("An humanoid Touched")
            local p = game.Players[hit.Parent.Name]
            print(hit.Parent.Name)
            local s = p:FindFirstChild("IsTouched")
            if s then
                print("Value found")
                print("Changing....")
                s.Value = true
                print("Changed!")
            end
        end
    end
end)

It work only one time and when i try a second time it doesn't

When i change the value manualy it works

it prints out everything on every tries i've made, even if the value does not change

Thanks for futur answers!

0
Lets assume that the deafult value of your ("IsTouched" Bool) is false so instead of doing if s then you could do if s.Value == false then s.Value = true else s.Value = false i think this is what u wanted it do it? ezkatka1 50 — 3y
0
And also you should probably add a debounce so that it doesn't fire multiple times if multiple body parts touch it ezkatka1 50 — 3y

Answer this question