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 a tool able to place?

Greetings, In my factory game, I have some traffic cones which I want to script to be able to place them in the workspace clicking in the part you want to place it.

How could I do that?

PD: I'm a novice scripter in Roblox, so I just know basics, and some other things.

3 comments

0

Please give more detail? To place them in the workspace? Like click on a position then make the cone appear there? If so here's a few articles to help. http://wiki.roblox.com/index.php?title=CFrame https://www.robloxdev.com/api-reference/function/Instance/Clone https://www.robloxdev.com/api-reference/property/Mouse/Hit

0

Isn't mouse.hit deprecated?

0

no

1 answer

✓ Accepted answer

Make a tool place? Ok sure here is code:

(Make a server script and a local script, also make a RemoteEvent in the tool)

In a local script (in tool)

local rEvent = script.Parent.RemoteEvent --the removeEvent
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	rEvent:FireServer(game.Players.LocalPlayer:GetMouse().Hit)
end)

In a server script (in tool)

local tool = script.Parent --the tool
local model = workspace.RandomModel --the model you want to clone
local rEvent = script.Parent.RemoteEvent --the removeEvent
rEvent.OnServerEvent:Connect(function(plr, cf)
	if plr.Character:FindFirstChild(tool.Name) then --check if tool is equipped
		local cl = model:Clone()
		if cl.ClassName == "Model" then
			cl:SetPrimaryPartCFrame(CFrame.new(cf.Position))
		else
			cl.CFrame = CFrame.new(cf.Position)
		end
	end 
end)

Does this help? If you have questions ask me!

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