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

How can I make sure a mine is only placed on a certain area?

Asked by
obcdino 113
8 years ago

So, I'm making a tycoon with a custom inventory. It has a button which gives you a tool to place a mine. The only problem is that you can place it anywhere you want in the game, and I want it to only be place-able on a baseplate. How can I do this?

Placing Script: (located inside a tool, and yes THE SCRIPT WORKS)

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:connect(function()
    local pos = mouse.hit.p
    local mine = script.Parent.StoneMine:Clone()
    mine.Parent = game.Workspace
    mine:MoveTo(pos)
    script.Parent:Destroy()
    for i,v in pairs(mine:GetChildren())do
        if v.ClassName == "Part" and v.Name ~= "Dropper" then
            v.Transparency = 0
            v.CanCollide = true
            v.Parent.Dropper.Transparency = 0.3
            v.Parent.Configuration.IsActive.Value = true
        end
    end
end)

1 answer

Log in to vote
1
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

mouse.Target is what the mouse clicked on.

I added a line that if the mouse clicked on anything other than the Baseplate it would return and end the function.

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:connect(function()
    local pos = mouse.hit.p
    if mouse.Target ~= 'Baseplate' then return end
    local mine = script.Parent.StoneMine:Clone()
    mine.Parent = game.Workspace
    mine:MoveTo(pos)
    script.Parent:Destroy()
    for i,v in pairs(mine:GetChildren())do
        if v.ClassName == "Part" and v.Name ~= "Dropper" then
            v.Transparency = 0
            v.CanCollide = true
            v.Parent.Dropper.Transparency = 0.3
            v.Parent.Configuration.IsActive.Value = true
        end
    end
end)

Ad

Answer this question