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

help with checking when key is pressed on a specific part?

Asked by 4 years ago

using a couple of different tutorials i created a code that when someone is on a part and they press e something would happen for testing purposes i made a sound play and to print pressed e when the player presses e the problem is the sound works fine but it keeps printing e wherever and not when the player is on the specific part could i please have some help?

here is my code.

debounce = false

script.Parent.Touched:connect(function(hit)

if not debounce then

        debounce = true
        if(hit.Parent:FindFirstChild("Humanoid")~=nil)then




        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local sound = script.Parent.Sound:Clone()
        sound.Parent = player.PlayerGui
        sound:Play()
        wait(5)
        local player = game.Players.LocalPlayer
        local mouse = player:GetMouse()

        mouse.KeyDown:connect(function(key)

            if key == "e" then

                print("Pressed e")
            end
        end)

     end
    debounce = false
end

end)

Answer this question