Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

First four parts stay where they are, last part gets removed. Howcome?

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)

11 comments

0

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?

0

It creates lag and just makes the place look messy.

0

Mouse.KeyDown is deprecated.

0

Also, why are you creating new KeyDown events every time?

0

On line3, you already created an event listener.

0

What do i use then?

0

So if i get rid of all the other event listeners will it fix my Destroy problem?

0

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.

0

And on line 8, remove the brackets as they are redundant.

0

Wait, why can't i use KeyDowns?

0

And i've removed all the other Event listens and now the script doesn't work

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.