-
What do you want to achieve?
I want his script to work on any model cuz I want to clone another object and delete the current object
-
What is the issue?
I just don’t know how to do it
-
What solutions have you tried so far?
look at developer hub
pt = workspace.model["SVT-40"] --i want this to work with any child in this wich is a model class
local plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
local prev
click = false
mouse.Button1Up:Connect(function()
click = false
end)
mouse.Button1Down:Connect(function()
click = true
end)
mouse.Move:Connect(function()
if click == true then
if mouse.Hit.p ~= prev then
pt.PrimaryPart.CFrame = CFrame.new(pt.PrimaryPart.Position, Vector3.new(mouse.Hit.p.x,mouse.Hit.p.y,mouse.Hit.p.z))
prev = mouse.Hit
end
end
end)
local plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
local prev
local click = false
mouse.Button1Up:Connect(function()
click = false
end)
mouse.Button1Down:Connect(function()
click = true
end)
mouse.Move:Connect(function()
if click == true then
if mouse.Hit.p ~= prev then
for _, model in ipairs(workspace:GetChildren()) do
if model:IsA("Model") then
model.PrimaryPart.CFrame = CFrame.new(model.PrimaryPart.Position, Vector3.new(mouse.Hit.p.x,mouse.Hit.p.y,mouse.Hit.p.z))
prev = mouse.Hit
end
end
end
end
end)
thx for your effort but i have prob Players.LAZY_DAISY001.Backpack.LocalScript:19: attempt to index nil with 'Position'
local script parent is starterpack
All of your models will need the “PrimaryPart” property set.
1 Like
Alternatively, you can exclude models which don’t have a “PrimaryPart” set with the following:
local plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
local prev
local click = false
mouse.Button1Up:Connect(function()
click = false
end)
mouse.Button1Down:Connect(function()
click = true
end)
mouse.Move:Connect(function()
if click == true then
if mouse.Hit.p ~= prev then
for _, model in ipairs(workspace:GetChildren()) do
if model:IsA("Model") then
if model.PrimaryPart then
model.PrimaryPart.CFrame = CFrame.new(model.PrimaryPart.Position, Vector3.new(mouse.Hit.p.x,mouse.Hit.p.y,mouse.Hit.p.z))
prev = mouse.Hit
end
end
end
end
end
end)
if mouse.Hit.p ~= prev then
prev = mouse.Hit
Just so you know that top conditional statement will always be true because you’re comparing mouse.Hit with mouse.Hit.p feel free to fix that if necessary.
great my whole workspace spinning
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local click = false
local prev
local pos
mouse.Button1Up:Connect(function()
click = false
end)
mouse.Button1Down:Connect(function()
click = true
pos = mouse.Hit.p
end)
mouse.Move:Connect(function()
if click then
if pos ~= prev then
for _, model in ipairs(workspace:GetChildren()) do
if model:IsA("Model") then
if model.PrimaryPart then
model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.Position, Vector3.new(mouse.Hit.p.x,mouse.Hit.p.y,mouse.Hit.p.z)))
prev = mouse.Hit.p
end
end
end
end
end
end)
You said you wanted this to work with every model?
1 Like
nvm i fixed it thx dude for _, model in ipairs(workspace.model:GetChildren()) do
(model frame)
Oh, it’s everything in that model, I thought you wanted it to work for all models, and no problem.
1 Like
wait and also i cant rotate the model smoothly it become choppy/cant rotate properly 360 what can i do?