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

How can I make a tool able to place?

Asked by
Time_URSS 146
5 years ago
Edited 5 years ago

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.

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 casper123123123 357 — 5y
0
Isn't mouse.hit deprecated? Abandion 118 — 5y
0
no Rare_tendo 3000 — 5y

1 answer

Log in to vote
1
Answered by
jaschutte 324 Moderation Voter
5 years ago

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!

Ad

Answer this question