Hey, Ive been having trouble for a few days now. I cant seem to Clone a Part thats suppose to be a Pet from Replicated Storage to a ViewPortFrame because it comes back as nil even though i know its there.
For context: I have similar code that instead of Cloning a Pet, it clones a Sword and that works and shows in the ViewPortFrame but when the Pet Code is in the script it limits the Sword GUI to 4 buy option when there are 11. Heres what is looks like now:
Heres what it should look like
Heres the Pets section of the GUI(The Selection button and the VPF bug out, overlap) :
Heres the Code where the problem happens(This is from a Local Script BTW):
local fakeCam = Instance.new("Camera")
fakeCam.Parent = box.VPF
local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
handle.Parent = box.VPF
box.VPF.CurrentCamera = fakeCam
fakeCam.CFrame = handle.CameraCFrame.Value
itemFrame["Item"..i].ItemName.Text = availableTools[i][1]
local budFakeCam = Instance.new("Camera")
budFakeCam.Parent = Bbox.VPF
local handle = game.ReplicatedStorage:WaitForChild("BuddyModels"):FindFirstChild(availableBuddys[i][1].."Pet"):Clone()
handle.Parent = Bbox.VPF
Bbox.VPF.CurrentCamera = budFakeCam
budFakeCam.CFrame = handle.CameraCFrame.Value
buddyFrame["Bud"..i].BItemName.Text = availableBuddys[i][1]
The Replicated Functions
local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local availableBuddys = game.ReplicatedStorage:WaitForChild("GetBud"):InvokeServer()
The Script that checks for the Invoke:
local module = {}
function module:Init()
game.ReplicatedStorage:WaitForChild("GetTools").OnServerInvoke = function(player)
local items = {}
for _, object in pairs(game.ServerStorage:WaitForChild("Items"):GetChildren())do
local itemProperties = {object.Name,object.Price.Value}
table.insert(items,itemProperties)
end
return items
end
game.ReplicatedStorage:WaitForChild("ItemCheck").OnServerInvoke = function(player,itemName)
if
game.ServerStorage.PlayerData:FindFirstChild(player.Name).Inventory:FindFirstChild(itemName)
then
return true
else
return false
end
end
game.ReplicatedStorage:WaitForChild("PurchaseItem").OnServerInvoke =
function(player,itemName)
local buxs = player.leaderstats.Buxs
local item = game.ServerStorage.Items:FindFirstChild(itemName)
if item then
--Item Exists
if game.ServerStorage.PlayerData[player.Name].Inventory:FindFirstChild(itemName)then
if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= itemName then
--Currently unequipped
game.ServerStorage.PlayerData[player.Name].Equipped.Value = itemName
return "Equipped"
else
game.ServerStorage.PlayerData[player.Name].Equipped.Value = ""
return "Unequipped"
end
end
if buxs.Value >= item.Price.Value then
buxs.Value = buxs.Value - item.Price.Value
local itemValue = Instance.new("ObjectValue")
itemValue.Name = itemName
itemValue.Parent = game.ServerStorage.PlayerData[player.name].Inventory
return true
else
return "NotEnoughBuxs"
end
else
return "NoItem"
end
end
end
game.ReplicatedStorage:WaitForChild("GetBud").OnServerInvoke = function(player)
local buditems = {}
for _, object in pairs(game.ServerStorage:WaitForChild("Buddys"):GetChildren())do
local buditemProperties = {object.Name,object.Price.Value}
--print(buditemProperties,buditems,#buditems,#buditemProperties)
table.insert(buditems,buditemProperties)
end
return buditems
end
game.ReplicatedStorage:WaitForChild("BuddyCheck").OnServerInvoke =
function(player,BitemName)
if game.ServerStorage.PlayerData:FindFirstChild(player.Name).BuddyInventory:FindFirstChild(BitemName) then
return true
else
return false
end
end
game.ReplicatedStorage:WaitForChild("BudPurchaseItem").OnServerInvoke =
function(player,BitemName)
local buxs = player.leaderstats.Buxs
local buditem = game.ServerStorage.Buddys:FindFirstChild(BitemName)
if buditem then
--Item Exists
if game.ServerStorage.PlayerData[player.Name].BuddyInventory:FindFirstChild(BitemName)then
if game.ServerStorage.PlayerData[player.Name].BuddyEquipped.Value ~= BitemName then
--Currently unequipped
game.ServerStorage.PlayerData[player.Name].BuddyEquipped.Value = BitemName
return "BuddyEquipped"
else
game.ServerStorage.PlayerData[player.Name].BuddyEquipped.Value = ""
return "BuddyUnequipped"
end
end
if buxs.Value >= buditem.Price.Value then
buxs.Value = buxs.Value - buditem.Price.Value
local itemValue = Instance.new("ObjectValue")
itemValue.Name = BitemName
itemValue.Parent = game.ServerStorage.PlayerData[player.name].BuddyInventory
return true
else
return "NotEnoughBuxs"
end
else
return "NoBuddy"
end
end
return module