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

How do I make a dropper that is connected to a button mechanism please help?!?

Asked by 8 years ago

Alright, so far in making a tycoon from scratch I have had good luck with finding out code (as it is my first time coding) but I cannot seem to find the command to put in a script that will spawn a block in a certain location, here is a snippet of that I have so far:

function onClicked(playerWhoClicked)
    script.Parent.BrickColor = BrickColor.Red()
    local points = playerWhoClicked.leaderstats.Copper
    points.Value = points.Value-1   --If I knew the command I would put it below this comand
    wait(1)    --Time it takes to cross conveyor
    local points = playerWhoClicked.leaderstats.Money
    points.Value = points.Value+5
    wait(4)
    script.Parent.BrickColor = BrickColor.Green()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Sorry my question is so simple I couldn't find it anywhere else and I am not giving up on making my fist code without any free models! So please if you know the command and how to implement it please let me know!

1 answer

Log in to vote
0
Answered by 8 years ago

I have made a quick example of a simple dropper, this kind of code can be found in a lot of free model tycoon builders:-

-- create click Brick
local tmpPart = Instance.new('Part', game.Workspace)
tmpPart.Anchored = true
tmpPart.Color = Color3.fromRGB(0,0,255)

local clicker = Instance.new('ClickDetector', tmpPart)

-- get the service
local debrisServ = game:GetService('Debris')
local blockLife = 10 -- 10 seconds

-- dropper
local dropper = Instance.new('Part', game.Workspace)
dropper.Anchored = true
dropper.CFrame = CFrame.new(0,15,-5)

-- the part that will be dropped
local dropPart = Instance.new('Part')
dropPart.Color = Color3.new(0,0,0)

-- add cash holder into the part
local cash = Instance.new('IntValue', dropPart)
cash.Name = 'cash'
cash.Value = 10

-- add the event
local deb = false
clicker.MouseClick:connect(function(plrClicked)
    if deb then return end
    deb = true
    -- change color on click
    tmpPart.Color = Color3.fromRGB(255,0,0)

    -- clone the part
    local clone = dropPart:Clone()
    -- this will also use the rotation of the dropper
    clone.CFrame = dropper.CFrame * CFrame.new(0, -3,0)
    debrisServ:AddItem(clone, blockLife)
    clone.Parent = game.Workspace

    wait(0.5)
    tmpPart.Color = Color3.fromRGB(0,0,255)
    deb = false
end)

As there may be a lot of new things here that you have not seen, please first check the wiki then post a comment. I will then update this question explaining the part of code as it would take too much time to explain all of the functions of this code.

Ad

Answer this question