01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local house = game.Lighting.House |
04 | target = game.Players.LocalPlayer:GetMouse().Target |
05 |
06 | script.Parent.MouseButton 1 Click:Connect( function () |
07 | wait(target) |
08 | local part = house:Clone() |
09 | part.Parent = workspace |
10 | part:SetPrimaryPartCFrame(Vector 3. new(target)) |
11 | end ) |
I have problem that been more than 2 months with trying and i didn't know how to fix it, i want the house copy at mouse position, I click the button then i click again and the house copy itself at second click position but Setprimarypartcframe isn't working, please help i am starting to get annoying for it.
First thing - you might want to name your variables something clearer - the part variable is a model right? Why not name it houseModel or something?
Anyway - the issue is that part:SetPrimaryPartCFrame() is expecting a CFrame, but you are passing a Vector3. This is a simple fix, just wrap your Vector3 in a CFrame contstructor:
01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local house = game.Lighting.House |
04 | target = game.Players.LocalPlayer:GetMouse().Target |
05 |
06 | script.Parent.MouseButton 1 Click:Connect( function () |
07 | wait(target) |
08 | local part = house:Clone() |
09 | part.Parent = workspace |
10 | part:SetPrimaryPartCFrame(CFrame.new(Vector 3. new(target))) |
11 | end ) |
Hope this helps, happy coding :)
There are 2 problems causing this error: You are creating a new Vector3 using an object as a parameter You are setting the CFrame of a part to a Vector3
The first problem is very easy to fix: Simply access the .Position property of target, and forget the entire Vector3.new() part, this'll give you the Vector3 you want.
The second problem is actually also quite easy to fix: If you want to set the CFrame of something to a new CFrame, you can do so by using CFrame.new(...) This'll accept 1-2 parameters, the first is the position, the second is what the CFrame points towards. In this case, use target.Position as the first parameter, and use that for :SetPrimaryPartCFrame()
Implementing these 2 changes, your code will look like this:
01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local house = game.Lighting.House |
04 |
05 | target = game.Players.LocalPlayer:GetMouse().Target |
06 |
07 | script.Parent.MouseButton 1 Click:Connect( function () |
08 | wait(target) |
09 | local part = house:Clone() |
10 | part.Parent = workspace |
11 | part:SetPrimaryPartCFrame(CFrame.new(target.Position)) |
12 | end ) |