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

Are there any ways to make this script shorter or more efficient? Both exploit and lines of code.

Asked by 4 years ago

I just started scripting and every time I make something I keep thinking is there a way to make this shorter or more efficient and because I don't have much knowledge about it I can't answer it, Here's a script I made for a basic dropper and furnace.

Leaderstats:

game.Players.PlayerAdded:Connect(function(Player)

    local leaderstats = Instance.new("Folder",Player)
    leaderstats.Name = "leaderstats"

    local Money = Instance.new("IntValue",leaderstats)
    Money.Name = "Money"

    local HasTycoon = Instance.new("BoolValue",Player)
    HasTycoon.Name = "HasTycoon"

end)

Gate:

local Door = script.Parent

Door.Touched:Connect(function(Hit)

    if Hit.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
        if not Player.HasTycoon.Value then
            local Owner = Instance.new("StringValue",game.Workspace.Tycoon)
            Owner.Name = "Owner"
            Owner.Value = Player.Name
            Door.Transparency = 1
            Door.CanCollide = false
            Player.HasTycoon.Value = true
            Door.Parent.BillboardGui.TextLabel.Text = ("Owner: "..Player.Name)
        end
    end

end)

Dropper

local Button = script.Parent
local ClickDetector = Button.ClickDetector
local Owner = game.Workspace.Tycoon:WaitForChild("Owner")
local Debounce = false

ClickDetector.MouseClick:Connect(function(Player)

    if not Debounce then
        if Owner.Value == Player.Name then
            Debounce = true
            Button.BrickColor = BrickColor.new("Camo")
            local Ore = Instance.new("Part",game.Workspace.Tycoon.StarterMine.StarterMineOres)
            Ore.Name = "Ore"
            Ore.BrickColor = BrickColor.new("Fossil")
            Ore.Material = "DiamondPlate"
            Ore.Size = Vector3.new(2,2,2)
            Ore.Position = Vector3.new(Button.Parent.Dropper.Position.X,Button.Parent.Dropper.Position.Y - 2,Button.Parent.Dropper.Position.Z)
            wait(0.3)
            Debounce = false
            Button.BrickColor = BrickColor.new("Lime green")
        end
    end

end)

Conveyor Belt:

local ConveyorSpeed = game.Workspace.Tycoon.Purchases.ConveyorSpeed
local ConveyorBelt = script.Parent

while wait() do
    ConveyorBelt.Velocity = ConveyorBelt.CFrame.lookVector * ConveyorSpeed.Value
end

Furnace:

local Lava = script.Parent
local Owner = game.Workspace.Tycoon:WaitForChild("Owner")

Lava.Touched:Connect(function(Ore)

    if Ore.Parent == game.Workspace.Tycoon.StarterMine.StarterMineOres then
        Ore:Destroy()
        game.Players[Owner.Value].leaderstats.Money.Value = game.Players[Owner.Value].leaderstats.Money.Value + 1
    end

end)

Answer this question