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