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

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.