The problem with pressing a button

Okay, here I have a script that when the player presses the “E” button it will teleport him to the nearest place. But for some reason, nothing happens)
Снимок экрана 2023-01-09 в 23.03.44

EButton.MouseButton1Click:Connect(onButtonPressed)

As I understood it, I had to replace the last line. I did that and nothing changed.)

I’m not sure what’s wrong with it, maybe you know?

Here is my code:

local player = game.Workspace.Player local plr = game.Players.LocalPlayer local char = plr.Character local mouse = plr:GetMouse() local find = game.Workspace:FindFirstChild(“Teleport”)

mouse.KeyDown:Connect(function(key) if key == “e” then

if (find ~= nil) then

char.HumanoidRootPart.CFrame = find.CFrame

end

end

end)

But it does not work.

The problem with removing a brick

Here is my code:

local Player = game.Players.LocalPlayer local Character = Player.Character local Mouse = Player:GetMouse() local Part = Instance.new(“Part”)

Part.Parent = workspace

Part.Position = workspace.CurrentCamera.CFrame.p

Part.Size = Vector3.new(10,10,10)

Part.Name = “A”

Part.Color = Color3.new(0,0,1)

Part.Anchored = true

Part.Locked = true

Part.CanCollide = false

Part.BrickColor = BrickColor.new(“Medium blue”)

Part.Material = “Neon”

Part.Transparency = 0.3

Part.Reflectance = 0.3

Part.TopSurface = “Smooth”

Part.BottomSurface = “Smooth”

Part.Shape = “Ball”

Mouse.Button1Down:Connect(function()

Part:Remove()

end)

But for some reason, it does not work.

Why are you using .Activated on UI for a key press? I think you should use UserInputService or ContextActionService to detect key presses instead.

Could you also send your code like this:

print("Hello world!")

image