hello so im trying to make a summoning system for my tower defense game but it gives me this error in output “observableValue undefined” and I dont know why. Can anyone help?
Heres the local script I can provide the sever script if needed.
local player = game.Players.LocalPlayer
local mainGui = player.PlayerGui:WaitForChild("MainGui")
local mainEvent = game.ReplicatedStorage:WaitForChild("MainEvent")
function closeFrames()
for i, v in pairs(mainGui:GetChildren()) do
for i2,v2 in pairs(v:GetChildren()) do
if v2:IsA("Frame") then
v2.Visible = false
end
end
end
end
mainGui.UnitsTextButton.MouseButton1Click:Connect(function()
closeFrames()
mainGui.UnitsTextButton.UnitsFrame.Visible = true
for i,v in pairs(mainGui.UnitsTextButton.UnitsFrame.OwnedUnits:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
for i,v in pairs(player.OwnedUnits:GetChildren()) do
local unitsTextButton = Instance.new("TextButton", mainGui.UnitsTextButton.UnitsFrame.OwnedUnits)
unitsTextButton.Name = v.Name.."TextButton"
unitsTextButton.Text = v.Name
unitsTextButton.BackgroundColor3 = Color3.new(0, 1, 1)
unitsTextButton.RichText = true
unitsTextButton.FontFace.Bold = true
unitsTextButton.TextScaled = true
end
mainGui.UnitsTextButton.UnitsFrame.CloseButton.MouseButton1Click:Connect(function()
closeFrames()
end)
end)
mainGui.SummonTextButton.MouseButton1Click:Connect(function()
closeFrames()
local summonFrame = mainGui.SummonTextButton.SummonFrame
mainGui.SummonTextButton.SummonFrame.CratesFrame.CoinsTextLabel.Text = "Coins: "..player.leaderstats.Coins.Value
summonFrame.Visible = true
mainGui.SummonTextButton.SummonFrame.CloseButton.MouseButton1Click:Connect(function()
closeFrames()
end)
summonFrame.CratesFrame.BasicCrate.MouseButton1Click:Connect(function()
summonFrame.CratesFrame.BasicCrate.BackgroundColor3 = Color3.new(0.33, 1, 0)
summonFrame.CratesFrame.MythicCrate.BackgroundColor3 = Color3.new(1, 0, 0)
end)
summonFrame.CratesFrame.MythicCrate.MouseButton1Click:Connect(function()
summonFrame.CratesFrame.MythicCrate.BackgroundColor3 = Color3.new(0.33, 1, 0)
summonFrame.CratesFrame.BasicCrate.BackgroundColor3 = Color3.new(1, 0, 0)
end)
summonFrame.CratesFrame.SummonButton.MouseButton1Click:Connect(function()
for i,v in pairs(summonFrame.CratesFrame:GetChildren()) do
if v:IsA("TextButton") then
if v.BackgroundColor3 == Color3.new(0.33, 1, 0) then
local crateName = string.split(v.Name, "TextButton")[1]
mainEvent:FireServer("Summon", crateName)
end
end
end
end)
end)
mainEvent.OnClientEvent:Connect(function(eventType, argument1)
if eventType == "Summon" then
local summonedUnit = argument1
local summonedTextLabel = mainGui.SummonTextButton.SummonFrame.CratesFrame.Summoned
summonedTextLabel.Text = "You have summoned: "..summonedUnit
mainGui.SummonTextButton.SummonFrame.CratesFrame.CoinsTextLabel.Text = "Coins: "..player.leaderstats.Coins.Value
end
end)
Well, I can’t deduce the case of that particular issue, I do see another one:
In this, you’re creating new event connections every time the SummonTextButton is clicked. This will create a memory leak as well as possibly spam your server:
If you click the main button more than once, and click the SummonButton more than once, this will fire the event a lot
Seems like you’re a step closer to the script’s problem then! Revise your script and UI elements with the notion that the client doesn’t seem to pick up on anything.
P-S: Don’t parent things with the Instance.new function.