local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'e' then
Part = Instance.new('Part', game.Workspace)
Part.Size = Vector3.new(2, 12,3)
Part.Material = ("Ice")
Part.CanCollide = false
Part.Anchored = true
Part.CFrame = Player.Character.Head.CFrame * CFrame.new(0,-2,-2)
wait(1)
Part:Destroy()
end
end)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'e' then
wait(0.1)
Part = Instance.new('Part', game.Workspace)
Part.Size = Vector3.new(2, 12,3)
Part.Material = ("Ice")
Part.CanCollide = false
Part.Anchored = true
Part.CFrame = Player.Character.Head.CFrame * CFrame.new(0,-2,-5)
wait(1)
Part:Destroy()
end
end)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'e' then
wait(0.2)
Part = Instance.new('Part', game.Workspace)
Part.Size = Vector3.new(2, 12,3)
Part.Material = ("Ice")
Part.CanCollide = false
Part.Anchored = true
Part.CFrame = Player.Character.Head.CFrame * CFrame.new(0,-2,-8)
wait(1)
Part:Destroy()
end
end)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'e' then
wait(0.3)
Part = Instance.new('Part', game.Workspace)
Part.Size = Vector3.new(2, 12,3)
Part.Material = ("Ice")
Part.CanCollide = false
Part.Anchored = true
Part.CFrame = Player.Character.Head.CFrame * CFrame.new(0,-2,-11)
wait(1)
Part:Destroy()
end
end)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'e' then
wait(0.4)
Part = Instance.new('Part', game.Workspace)
Part.Size = Vector3.new(2, 12,3)
Part.Material = ("Ice")
Part.CanCollide = false
Part.Anchored = true
Part.CFrame = Player.Character.Head.CFrame * CFrame.new(0,-2,-15)
wait(1)
Part:Destroy()
end
end)
COMMUNITY QUESTION
First four parts stay where they are, last part gets removed. Howcome?
1 answer
First of all, KeyDown is deprecated. It works in Studio but not in the actual game. Second, you wasted a lot of time making the same variables over and over. Same with all the extra functions.
Instead of using KeyDown, use the UserInputService. Also, don't make the same variables and functions over and over.
A shortened example of what you're doing:
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gpe)
if not gpe and input.KeyCode == Enum.Q then
part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.CFrame = player.Character.Head.CFrame * CFrame.new(0, -2, -15)
wait(1)
part:Destroy()
wait()
partA = Instance.new("Part", game.Workspace)
partA.Anchored = true
partA.CFrame = player.Character.Head.CFrame * CFrame.new(0, -2, -15)
wait(1)
partA:Destroy()
end
end)
These are a couple mistakes. The answer to your question is lag...... I think. Also, even if Keydown wasn't deprecated, its pointless to do the "Key = Key:lower()" part. Hope this helps
2 comments
0
Line 5 and 11 have deprecated code. The parent parameter of Instance.new is deprecated.
0
Oh alrighty, thanks mate
This discussion is preserved as it was. New answers, comments, and votes are closed.

11 comments
The title didn't let me explain all the details, so what i'm trying to figure out is why does the last part only get destroyed and the first four parts stay where they are when they appear?
It creates lag and just makes the place look messy.
Mouse.KeyDown is deprecated.
Also, why are you creating new KeyDown events every time?
On line3, you already created an event listener.
What do i use then?
So if i get rid of all the other event listeners will it fix my Destroy problem?
Remove all of the event listens except for line 3. There was no need to create new ones. You shouldn’t be using KeyDown anyways.
And on line 8, remove the brackets as they are redundant.
Wait, why can't i use KeyDowns?
And i've removed all the other Event listens and now the script doesn't work