Player presses key, if touching a certain part with a certain name then continue code, how would I do this?
--doctorbenny2011 09/04/2016 15:45GMT istouching = false local Player = game.Players.LocalPlayer repeat wait(.01) until Player.Character local Mouse = Player:GetMouse() local Animated = false Player.Character["Left Leg"].Touched:connect(function(hit) if hit then if hit.Name == "Matress" then istouching = true elseif hit.Name ~= "Matress" then istouching = false end end end) Mouse.KeyDown:connect(function(key) local Animation = Instance.new("Animation") if key == "c" then if istouching == true then game.Workspace.BasePlate.CFrame = game.Workspace.BasePlate.CFrame * CFrame.Angles(0,1,0) end end end)
You might be able to use Touch and TouchEnded.
tv = 0 function pint() print ("touch"..tv) tv = tv +1 end function upint() print "touch ended" end script.Parent.Touched:connect(pint) script.Parent.Touched:connect(upint)
something like that should work. It won't work very well, but it will work.
--doctorbenny2011 09/04/2016 15:45GMT istouching = false local Player = game.Players.LocalPlayer repeat wait(.01) until Player.Character local Mouse = Player:GetMouse() local Animated = false --UserInputFunction Matress.Touched:connect(function(touched) --Detects when touched & define matress if touched.Parent.Humanoid == true then istouching = true end end Matress.TouchedEnded:connect(function() -- Detects when touched ended istouching = false end Mouse.KeyDown:connect(function(key) local Animation = Instance.new("Animation") if key == "c" then if istouching == true then --Code end end end)