I am trying to make a tycoon sort of game, and so if you have 5$ and interact with a red circle to buy a worker, a worker appears and stands where the red circle was.
Whats happening is I interact with it, and it comes up with this error "Position is not a valid member of Model “Workspace.Trooper/Corporal” The Trooper still goes to workspace though.
Heres the code:
script.Parent.Triggered:Connect(function(plr)
if plr.Team==game.Teams.Imperial then
if plr.leaderstats.Money.Value>=5 then
local newWorker=game.ReplicatedStorage["Trooper/Corporal"]:Clone()
newWorker.Parent=game.Workspace
newWorker.Position=Vector3.new(-43.375, 0.125, -8.5)
plr.leaderstats.Money.Value=-5
script.Parent.Parent:Destroy()
end
end
end)```
Models do not have the .Position Property. Instead to move models use :PivotTo(CFRAME) to move models to your desired position. It will require CFrame instead of Vector3 though. You can convert your Vector3 value to a CFrame value doing this.
Id suggest using :PivotTo() considering that method is inferior according to Roblox considering :SetPrimaryPartCFrame and :GetPrimaryPartCFrame are depricated. :PivotTo() doesnt require you to set a primary part so its basically just a successor to the Primary Part method. You can still do it the way you wish though.
script.Parent.Triggered:Connect(function(plr)
if plr.Team==game.Teams.Imperial then
if plr.leaderstats.Money.Value>=5 then
local newWorker=game.ReplicatedStorage["Trooper/Corporal"]:Clone()
newWorker.Parent=game.Workspace
newWorker.Position=Vector3.new(-43.375, 0.125, -8.5)
plr.leaderstats.Money.Value=-5
script.Parent.Parent:Destroy()
end
end
end)```
It says this: Unable to cast double to CoordinateFrame
Heres my code
if plr.Team==game.Teams.Imperial then
if plr.leaderstats.Money.Value>=5 then
local newWorker=game.ReplicatedStorage["Trooper/Corporal"]:Clone()
newWorker.Parent=game.Workspace
newWorker:PivotTo(-43.375, 0.125, -8.5)
plr.leaderstats.Money.Value=-5
script.Parent.Parent:Destroy()
end
end
end)```