Ok, so I’m using a shop script for a simulator game I am making that is partially code I found online, some I wrote myself. However, only some of the tools are showing up. Below is a video that should explain what’s happening. I’m not sure what the problem is, because only some of the items show up, even though they are all basically the same besides their meshes.
robloxapp-20230324-1709001.wmv (1.2 MB)
Below is the script:
script.Parent.Enabled = false
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local buyableItems = game.ReplicatedStorage:WaitForChild("BuyableItems"):GetChildren()
table.sort(buyableItems, function(a, b)
return (a.Price.Value < b.Price.Value)
end)
local standTemplate = game.ReplicatedStorage:WaitForChild("StandTemplate")
local itemBoughtRE = game.ReplicatedStorage:WaitForChild("OnItemBought")
local isInShop = false
local tweenService, tweenInfo = game:GetService("TweenService"), TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
humanoid.Touched:Connect(function(touchedPart)
if touchedPart == workspace.Map.Shop.ShopPad then
if isInShop then return end
isInShop = true
script.Parent.Enabled = true
char.HumanoidRootPart.Anchored = true
local currentStand = 1
local function updateBuyBtn()
local weapon = buyableItems[currentStand]
local price = weapon.Price.Value
local name = weapon.Name
if not plr.Backpack:FindFirstChild(weapon.Name) and not char:FindFirstChild(weapon.Name) then
script.Parent.BuyButton.BuyText.Text = "Buy " .. name .. " for " .. price
script.Parent.BuyButton.ImageColor3 = Color3.fromRGB(0, 200, 107)
else
script.Parent.BuyButton.BuyText.Text = "Already Owned!"
script.Parent.BuyButton.ImageColor3 = Color3.fromRGB(122, 121, 130)
end
end
plr.Backpack.ChildAdded:Connect(updateBuyBtn)
local stands = {}
for i, buyableItem in pairs(buyableItems) do
local stand = standTemplate:Clone()
stand.Stand.CFrame = stand.Stand.CFrame + Vector3.new(i * 5, 0, 0)
stand.CameraPart.CFrame = stand.CameraPart.CFrame + Vector3.new(i*5, 0, 0)
stand.Parent = workspace
table.insert(stands, stand)
local itemClone = buyableItem:Clone()
itemClone.Handle.CFrame = stand.Stand.CFrame + Vector3.new(0, 3, 0)
itemClone.Handle.CanCollide = false
itemClone.Parent = stand
local bav = Instance.new("BodyAngularVelocity")
bav.Parent = itemClone.Handle
bav.AngularVelocity = Vector3.new(0, 1, 0)
local bp = Instance.new("BodyPosition")
bp.Parent = itemClone.Handle
bp.Position = itemClone.Handle.Position
end
local originalCamCFrame = camera.CFrame
camera.CameraType = Enum.CameraType.Scriptable
tweenService:Create(camera, tweenInfo, {CFrame = stands[1].CameraPart.CFrame}):Play()
updateBuyBtn()
script.Parent.LeftArrowButton.MouseButton1Click:Connect(function()
local newStand = currentStand - 1
if newStand > 0 then
currentStand = newStand
updateBuyBtn()
tweenService:Create(camera, tweenInfo, {CFrame = stands[newStand].CameraPart.CFrame}):Play()
end
end)
script.Parent.RightArrowButton.MouseButton1Click:Connect(function()
local newStand = currentStand + 1
if newStand <= #buyableItems then
currentStand = newStand
updateBuyBtn()
tweenService:Create(camera, tweenInfo, {CFrame = stands[newStand].CameraPart.CFrame}):Play()
end
end)
script.Parent.ExitButton.MouseButton1Click:Connect(function()
tweenService:Create(camera, tweenInfo, {CFrame = originalCamCFrame}):Play()
wait(0.5)
camera.CameraType = Enum.CameraType.Custom
char.HumanoidRootPart.Anchored = false
script.Parent.Enabled = false
for i, stand in pairs(stands) do
stand:Destroy()
end
wait(1)
isInShop = false
end)
script.Parent.BuyButton.MouseButton1Click:Connect(function()
local itemBuying = buyableItems[currentStand]
itemBoughtRE:FireServer(itemBuying)
end)
end
end)
Any help is greatly appreciated