local Plank = workspace.Plank local Numbers = Plank.Folder local Mouse = Plrs.LocalPlayer:GetMouse() local Dist = 10 local Mag = (Plank.Position - Dist).Magnitude Mouse.KeyDown:Connect(function(Key) if Mag <= Dist then if Key == "A" then print("In range!") end else print("Not in range!") end end)
I'm trying to make it so that when you click this plank it plays a sound which resembles knocking on wood; it's only supposed to work when the player is within 10 units of the plank though. It seems it does not print "In range!" though. Why?
you should use a click detector.
insert a click detector into the plank and set its max distance to 10 and create a script that detects the activation
script.Parent.ClickDetector.MaxActivationDistance = 10 script.Parent.ClickDetector.MouseClick:Connect(function() print("Clicked") end)
Replace KeyDown on line 8 with MouseButton1Down and get rid of the key parameter. Since you want a key press too, use UserInputService. You can read about it on the dev wikia. The reason your script doesn’t work is because key doesn’t work on mouse. Let me know if this helped you.