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

Unable to cast double to CoordinateFrame?

Asked by 8 years ago

Trying to make it where when a Player presses 'Q', the model clones to the workspace and the player can place it wherever they please on a 1 stud increment. I keep getting the error: "Unable to cast double to CoordinateFrame"

01local model = game.ReplicatedStorage.Model
02 
03local mouse = game.Players.LocalPlayer:GetMouse()
04 
05 
06 
07 
08mouse.KeyDown:connect(function(key)
09    if key == "q" then
10        local newModel = model:Clone()
11        newModel.Parent = game.Workspace
12        newModel:SetPrimaryPartCFrame(mouse.X,mouse.Y)
13    end
14end)

1 answer

Log in to vote
0
Answered by 8 years ago

The SetPrimaryPartCFrame requires a CFrame value but instead you gave it two values; mouse.X, and mouse.Y If you're trying to move it by 1 stud increments, you're going to have to use math.floor or math.ceil

01local model = game.ReplicatedStorage.Model
02 
03local mouse = game.Players.LocalPlayer:GetMouse()
04 
05 
06 
07 
08mouse.KeyDown:connect(function(key)
09    if key == "q" then
10        local newModel = model:Clone()
11        newModel.Parent = game.Workspace
12        newModel:SetPrimaryPartCFrame(CFrame.new(math.floor(mouse.Hit.p.X),math.floor(mouse.Hit.p.Y),math.floor(mouse.Hit.p.Z)))
13    end
14end)

That should work.

Ad

Answer this question