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

How do you make it so when you click anywhere with a Tool it clones a Model?

Asked by 10 years ago

I want to make it so when you click anywhere on a Tool, it Clones the model to where the Player's mouse clicks. Does anyone know how to get started on this?

2 answers

Log in to vote
1
Answered by
MrNicNac 855 Moderation Voter
10 years ago

Assuming your model is in the ReplicatedStorage service (which it should be), this LocalScript (which should be placed in the StarterGui or StarterPack) will put a clone of that model wherever the user clicks. Only when a part is clicked, of course.

NOTE: This also checks and will work with a part or a model.

local p = Game.Players.LocalPlayer
local m = p:GetMouse();
local model = Game.ReplicatedStorage['Model Name'];

m.Button1Down:connect(function()
    if m.Target then
        local x = model:Clone()
        if x:IsA("Model") then
            x.Parent = Workspace
            x:MoveTo(m.Hit.p)
        elseif x:IsA("BasePart") then
            x.Parent = Workspace
            x.Position = m.Hit.p
        end
    end
end)

0
It didn't work. I clicked on the Base and nothing happened, and same with a Part. I also changed the Model name to the Model and put it in ReplicatedStorage, xXScorpianKillerXx 25 — 10y
0
I've edited to fix the bug. I was using MouseButton1Down when it should be Button1Down. The clone was also never parented. MrNicNac 855 — 10y
0
Thank's it works. But I have a question. Whenever I click it makes the Model. Do you know how to fix it so it only clones when you click with the Tool? I even put the script in the tool but it clones without it. xXScorpianKillerXx 25 — 10y
0
Shouldn't be too difficult. Learn how to use the Equipped event of a tool to get the mouse. Instead of using 'm' from GetMouse(), use the Equipped event of a tool to get the mouse. MrNicNac 855 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

For getting the position where the Player's mouse clicks use mouse.Hit. Then :Clone() the model from ReplicatedStorage.

Answer this question