Roblox studio is so bad

WHEN I RUN A FUNCTION IN THE SERVER SIDE IT WORKS BUT WHEN I INVOKE IT IT JUST SAYS “nuh uh and wompity womp im not gonna work so go deal with it” LIKE WHAT IT ALSO DOESNT PRINT ANYTHING, IM LOSING MY SANITY OVER THIS HELP HELP HELP HELP PLS LIKE IS MY CODE BAD OR IS ROBLOX AT FAULtlocal defaultData = {
[“Gold”] = 3333,
[“SelectedTowers”] = {“Gunner”},
[“OwnedTowers”] = {“Gunner”},
}

local function GetStatus(item)
print(item)
local playerData = defaultData
if table.find(playerData.SelectedTowers, item) then
return “Unequip”
elseif table.find(playerData.OwnedTowers, item) then
return “Equip”
else
return “For Sale”
end
end
local function OnInteracted(item)
local shopItem = TowerShop[item]
local playerData = defaultData

if shopItem and playerData then
	local status = GetStatus(item)
	if status == "For Sale" and shopItem.Price <= playerData.Gold then
		print("OK")
		playerData.Gold = playerData.Gold - shopItem.Price
		table.insert(playerData.OwnedTowers, shopItem.Name)
	elseif status == "Equip" then
		table.insert(playerData.SelectedTowers, shopItem.Name)
		if #playerData.SelectedTowers > MAX_SELECTED_TOWERS then
			table.remove(playerData.SelectedTowers, 1)
		end
	elseif status == "Unequip" then
		local towerToRemove = table.find(playerData.SelectedTowers, item)
		table.remove(playerData.SelectedTowers, towerToRemove)
	end
	return playerData
end

return false

end

ReplicatedStorage.InteractItem.OnServerInvoke = OnInteractedlocal TowerShop = {
[“Gunner”] = {
[“Name”] = “Gunner”,
[“Price”] = 0,
[“Description”] = “The most fundamental tower in the game. Equipped with a pistol, it targets and eliminates foes. Available from level 0.”
},
[“Trooper”] = {
[“Name”] = “Trooper”,
[“Price”] = 1000,
[“Description”] = “Equipped with an AR, this unit swiftly eliminates weak zombies while still dealing significant damage to later hordes.”
},
[“Sharpshooter”] = {
[“Name”] = “Sharpshooter”,
[“Price”] = 1300,
[“Description”] = ‘Snipes enemies from large distances, inflicts big damage, but has a slow firerate.’
},
[“Bulletstormer”] = {
[“Name”] = “Bulletstormer”,
[“Price”] = 4000,
[“Description”] = “Absolute Bullet Blitzkrieg.”
},
}

return TowerShoplocal function interactItem(item, shop)
print(item, item.Name)
local data = InteractItem:InvokeServer(item.Name)

if data then
	playerData = data
	for i, v in data.OwnedTowers do
		print(i,v)
	end
	UpdateInfo(item, shop)
else
	print("No data received from server.")
end

end

local function GetStatus(item)
if table.find(playerData.SelectedTowers, item) then
return “Unequip”
elseif table.find(playerData.OwnedTowers, item) then
return “Equip”
else
return “For Sale”
end
end

function UpdateInfo(tower, isShop)
local infoPanel = (isShop and Info) or invInfo
local modelName = (isShop and tower.Name) or tower

local status = GetStatus(modelName)

-- Update UI elements with tower information
infoPanel.Title.Text.Text = modelName
if status == "For Sale" and isShop then
	infoPanel.Description.Text.Text = tower.Description
	infoPanel.Buy.Text = "$" .. tostring(tower.Price)
elseif status ~= "For Sale" and isShop then
	infoPanel.Buy.Text = "Owned"
elseif status ~= "For Sale" and not isShop then
	infoPanel.Equip.Text = status
end

-- Find and configure tower model
local model = towers:FindFirstChild(modelName)
if model then
	local config = model:WaitForChild("Configurations")

	-- Update tower stats
	for _, statFrame in pairs(infoPanel.TowerStats:GetChildren()) do
		if statFrame:IsA("Frame") then
			if statFrame.Name ~= "TotalDPS" then
				statFrame.Description.Text = statFrame.Name .. ": " .. tostring(config.Stats[statFrame.Name].Value)
			else
				statFrame.Description.Text = "Total DPS: " .. math.floor((config.Stats.Damage.Value / config.Stats.Cooldown.Value) * 100 + 0.5) / 100
			end
		end
	end
else
	print("Model not found:", modelName)
end

infoPanel.Description.Text.Text = towerShop[modelName].Description

-- Clear old model in viewport
infoPanel.ViewportFrame.WorldModel:ClearAllChildren()

-- Add new tower model to viewport
local newTower = model:Clone()
newTower.HumanoidRootPart.Position = Vector3.new(0, -0.15, -2)
newTower.HumanoidRootPart.CFrame = newTower.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(115), 0)
newTower.Parent = workspace
PlayAnimation(newTower, "Idle")
newTower.Parent = infoPanel.ViewportFrame.WorldModel

if infoPanel:FindFirstChild("Buy") then
	infoPanel.Buy.Activated:Connect(function()
		interactItem(tower, true)
	end)
else
	infoPanel.Equip.Activated:Connect(function()
		interactItem(tower, false)
	end)
end

end

function UpdateItems(isShop)
local itemList = (isShop and towerShop) or playerData.OwnedTowers
local canvas = isShop and Canvas or invCanvas

for _, tower in pairs(itemList) do
	local name = tower.Name or tower

	-- Destroy existing button if it exists
	local oldButton = canvas:FindFirstChild(name)
	if oldButton then
		oldButton:Destroy()
	end

	-- Create a new button
	local newButton = canvas.Placeholder:Clone()
	newButton.Name = name
	newButton.Template.TowerName.Text = name

	-- Clone and set up the tower model
	local foundTower = towers:FindFirstChild(name)
	if foundTower then
		local newTower = foundTower:Clone()
		newTower.HumanoidRootPart.Position = Vector3.new(0, -0.15, -2.5)
		newTower.HumanoidRootPart.CFrame = newTower.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(115), 0)
		newTower.Parent = workspace
		PlayAnimation(newTower, "Idle")
		newTower.Parent = newButton.Template.ViewportFrame.WorldModel
	end

	-- Set visibility and layout order
	newButton.Visible = true
	newButton.LayoutOrder = tower.Price or foundTower.Configurations.Financial.Price.Value

	-- Set parent to canvas
	newButton.Parent = canvas

	-- Connect button activation to function
	newButton.Template.Button.Activated:Connect(function()
		newButton.Template.Clicked:Play()
		UpdateInfo(tower, isShop)
	end)
end

end

2 Likes

If you want i can provide the scripts more clearly

1 Like

I’ll actually take a moment and see if anyone will help you.

2 Likes

Server:

-- Default Player Data
local defaultData = {
    ["Gold"] = 3333,
    ["SelectedTowers"] = {"Gunner"},
    ["OwnedTowers"] = {"Gunner"},
}

-- TowerShop Configuration
local TowerShop = {
    ["Gunner"] = {
        ["Name"] = "Gunner",
        ["Price"] = 0,
        ["Description"] = "The most fundamental tower in the game. Equipped with a pistol, it targets and eliminates foes. Available from level 0."
    },
    ["Trooper"] = {
        ["Name"] = "Trooper",
        ["Price"] = 1000,
        ["Description"] = "Equipped with an AR, this unit swiftly eliminates weak zombies while still dealing significant damage to later hordes."
    },
    ["Sharpshooter"] = {
        ["Name"] = "Sharpshooter",
        ["Price"] = 1300,
        ["Description"] = "Snipes enemies from large distances, inflicts big damage, but has a slow firerate."
    },
    ["Bulletstormer"] = {
        ["Name"] = "Bulletstormer",
        ["Price"] = 4000,
        ["Description"] = "Absolute Bullet Blitzkrieg."
    },
}

-- Utility Function: Get Status
local function GetStatus(item, playerData)
    if table.find(playerData.SelectedTowers, item) then
        return "Unequip"
    elseif table.find(playerData.OwnedTowers, item) then
        return "Equip"
    else
        return "For Sale"
    end
end

-- OnInteracted Function
local function OnInteracted(player, item)
    print("OnInteracted invoked with item:", item)
    local shopItem = TowerShop[item]
    local playerData = defaultData -- Replace this with your actual data-fetching logic for the player

    if not shopItem or not playerData then
        print("Invalid shop item or player data")
        return false
    end

    local status = GetStatus(item, playerData)
    print("Item status:", status)

    if status == "For Sale" and shopItem.Price <= playerData.Gold then
        print("Purchasing item:", item)
        playerData.Gold = playerData.Gold - shopItem.Price
        table.insert(playerData.OwnedTowers, shopItem.Name)
    elseif status == "Equip" then
        print("Equipping item:", item)
        table.insert(playerData.SelectedTowers, shopItem.Name)
        if #playerData.SelectedTowers > 3 then -- Adjust MAX_SELECTED_TOWERS as needed
            table.remove(playerData.SelectedTowers, 1)
        end
    elseif status == "Unequip" then
        print("Unequipping item:", item)
        local towerToRemove = table.find(playerData.SelectedTowers, item)
        table.remove(playerData.SelectedTowers, towerToRemove)
    else
        print("Unable to process interaction for item:", item)
        return false
    end

    return playerData
end

game:GetService("ReplicatedStorage").InteractItem.OnServerInvoke = OnInteracted

Client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TowerShop = {
    ["Gunner"] = {
        ["Name"] = "Gunner",
        ["Price"] = 0,
        ["Description"] = "The most fundamental tower in the game. Equipped with a pistol, it targets and eliminates foes. Available from level 0."
    },
    ["Trooper"] = {
        ["Name"] = "Trooper",
        ["Price"] = 1000,
        ["Description"] = "Equipped with an AR, this unit swiftly eliminates weak zombies while still dealing significant damage to later hordes."
    },
    ["Sharpshooter"] = {
        ["Name"] = "Sharpshooter",
        ["Price"] = 1300,
        ["Description"] = "Snipes enemies from large distances, inflicts big damage, but has a slow firerate."
    },
    ["Bulletstormer"] = {
        ["Name"] = "Bulletstormer",
        ["Price"] = 4000,
        ["Description"] = "Absolute Bullet Blitzkrieg."
    },
}

-- Client Player Data
local playerData = {
    ["Gold"] = 3333,
    ["SelectedTowers"] = {"Gunner"},
    ["OwnedTowers"] = {"Gunner"},
}

-- Utility Function: Get Status
local function GetStatus(item)
    if table.find(playerData.SelectedTowers, item) then
        return "Unequip"
    elseif table.find(playerData.OwnedTowers, item) then
        return "Equip"
    else
        return "For Sale"
    end
end

-- Interact Item
local function interactItem(item, isShop)
    print("Interacting with item:", item.Name)
    local data = ReplicatedStorage.InteractItem:InvokeServer(item.Name)

    if data then
        print("Data received from server:", data)
        playerData = data
        for i, v in pairs(data.OwnedTowers) do
            print("Owned Tower:", i, v)
        end
        UpdateInfo(item, isShop)
    else
        print("No data received from server.")
    end
end

-- Update Info Panel
function UpdateInfo(tower, isShop)
    print("Updating info panel for:", tower.Name)
    local infoPanel = isShop and Info or invInfo
    local modelName = isShop and tower.Name or tower

    local status = GetStatus(modelName)

    -- Update UI elements
    infoPanel.Title.Text.Text = modelName
    if status == "For Sale" and isShop then
        infoPanel.Description.Text.Text = tower.Description
        infoPanel.Buy.Text = "$" .. tostring(tower.Price)
    elseif status ~= "For Sale" and isShop then
        infoPanel.Buy.Text = "Owned"
    elseif status ~= "For Sale" and not isShop then
        infoPanel.Equip.Text = status
    end
end

Let me know if that works, or doesn’t

Please do. What you’ve given us is very difficult to digest. Make sure not to exclude any code. Please elaborate on what specifically about your script(s) isn’t working, and what the intended behaviour is