So i'm trying to make a model teleport to certain coordinates, but the problem is i need it to duplicate. Instead of just teleporting the same model each time i need it to teleport a new model with the same contents.
My code so far:
Case = game.ServerStorage.Case:Clone() Case.Parent = game.Workspace function onClicked(Part) Case:SetPrimaryPartCFrame(CFrame.new(99, 2.5, 55.5)) game.Players.LocalPlayer.Backpack.Case:Destroy() end script.Parent.ClickDetector.MouseClick:connect (onClicked)
What it currently Does: https://gyazo.com/aa821d1c24f168dd0b062dc8353bdd0f
So i need it to do what it currently does except instead of teleporting the same model back i want it to make a new model with the same contents and teleport it.
I tried to word this as best i could.
What you've done is only made it clone once when the script runs for the first time, if you want it to be cloned each time it's clicked put the cloning line in the on clicked function like so:
function onClicked(Part) -- Part is the player that clicked it... Case = game.ServerStorage.Case:Clone() -- Moved into the function Case.Parent = game.Workspace -- Moved into the function Case:SetPrimaryPartCFrame(CFrame.new(99, 2.5, 55.5)) game.Players.LocalPlayer.Backpack.Case:Destroy() -- LocalPlayer is nil because this isn't in a player end script.Parent.ClickDetector.MouseClick:connect (onClicked)
Also, to avoid it erroring if the player doesn't have a backpack check it before removing it, It also looks like you're trying to make it look as if it's taking there bag, if you are use this:
function onClicked(player) -- Changed to player so it makes more sense if player.Backpack:FindFirstChild("Case") ~= nil then -- If they have a case Case = game.ServerStorage.Case:Clone() -- Moved into the function Case.Parent = game.Workspace -- Moved into the function Case:SetPrimaryPartCFrame(CFrame.new(99, 2.5, 55.5)) end end script.Parent.ClickDetector.MouseClick:connect (onClicked)