Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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)
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? Alphagoreguy -2 — 5y
0
It creates lag and just makes the place look messy. Alphagoreguy -2 — 5y
0
Mouse.KeyDown is deprecated. User#19524 175 — 5y
0
Also, why are you creating new KeyDown events every time? User#19524 175 — 5y
View all comments (7 more)
0
On line3, you already created an event listener. User#19524 175 — 5y
0
What do i use then? Alphagoreguy -2 — 5y
0
So if i get rid of all the other event listeners will it fix my Destroy problem? Alphagoreguy -2 — 5y
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. User#19524 175 — 5y
0
And on line 8, remove the brackets as they are redundant. User#19524 175 — 5y
0
Wait, why can't i use KeyDowns? Alphagoreguy -2 — 5y
0
And i've removed all the other Event listens and now the script doesn't work Alphagoreguy -2 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

0
Line 5 and 11 have deprecated code. The parent parameter of Instance.new is deprecated. User#19524 175 — 5y
0
Oh alrighty, thanks mate Alphagoreguy -2 — 5y
Ad

Answer this question