Hey so I made a summoning script for summoning units and then it will put the units text label into their inventory but its not working and it doesnt say anything in output. Can anyone help?
Heres the local script i can provide the server 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)
local coreDataStore = game:GetService("DataStoreService"):GetDataStore("CoreDatastore")
local mainEvent = game.ReplicatedStorage:WaitForChild("MainEvent")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 100000
coins.Parent = leaderstats
local ownedUnits = Instance.new("Folder")
ownedUnits.Name = "OwnedUnits"
ownedUnits.Parent = player
local key = player.UserId
local success, errormessage = pcall(function()
local data = coreDataStore:GetAsync(key)
if data then
coins.Value = data[1]
for i,v in pairs(data) do
if i > 1 then
local ownedUnit = Instance.new("BoolValue", ownedUnits)
ownedUnit.Name = v
ownedUnit.Value = true
end
end
end
end)
while not success do
local data = coreDataStore:GetAsync(key)
if data then
coins.Value = data[1]
for i,v in pairs(data) do
if i > 1 then
local ownedUnit = Instance.new("BoolValue", ownedUnits)
ownedUnit.Name = v
ownedUnit.Value = true
end
end
end
task.wait(4)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = player.UserId
local success, errormessage = pcall(function()
local dataTable = {}
table.insert(dataTable, player.leaderstats.Coins.Value)
for i,v in pairs(player.OwnedUnits:GetChildren()) do
table.insert(dataTable, v.Name)
end
coreDataStore:SetAsync(key, dataTable)
end)
while not success do
local key = player.UserId
local success, errormessage = pcall(function()
local dataTable = {}
table.insert(dataTable, player.leaderstats.Coins.Value)
for i,v in pairs(player.OwnedUnits:GetChildren()) do
table.insert(dataTable, v.Name)
end
coreDataStore:SetAsync(key, dataTable)
task.wait(4)
end)
end
end)
local basicCrateChances = {
["BurgerMan"] = 100;
["FrenchFryMan"] = 75;
["Customer"] = 50;
}
local totalChance = 0
for i,v in pairs(basicCrateChances) do
totalChance += v
end
local mythicCrateChances = {
["MilkShakeMan"] = 100;
["IcecreamMan"] = 75;
["RamenMan"] = 50;
}
local totalChance2= 0
for i,v in pairs(mythicCrateChances) do
totalChance2 += v
end
mainEvent.OnServerEvent:Connect(function(player, eventType, argument1)
if eventType == "Summon" then
local crateName = argument1
if crateName == "Basic Crate" and player.leaderstats.Coins.Value >= 100 then
local maybeChance = 0
local randomNumber = math.random(1, totalChance)
for i,v in pairs(basicCrateChances) do
maybeChance += v
if randomNumber <= maybeChance then
player.leaderstats.Coins.Value -= 100
mainEvent:FireClient(player, "Summon", i)
if not player.OwnedUnits:FindFirstChild(i) then
local ownedUnit = Instance.new("BoolValue", player.OwnedUnits)
ownedUnit.Name = i
ownedUnit.Value = true
end
break
end
end
elseif crateName == "Mythic Crate" and player.leaderstats.Coins.Value >= 1200 then
local maybeChance2 = 0
local randomNumber2 = math.random(1, totalChance2)
for i,v in pairs(mythicCrateChances) do
maybeChance2 += v
if randomNumber2 <= maybeChance2 then
player.leaderstats.Coins.Value -= 1200
mainEvent:FireClient(player, "Summon", i)
if not player.OwnedUnits:FindFirstChild(i) then
local ownedUnit = Instance.new("BoolValue", player.OwnedUnits)
ownedUnit.Name = i
ownedUnit.Value = true
end
break
end
end
end
end
end)
robloxapp-20240906-1638293.wmv (739.4 KB)
So when i press the summon button it doesnt show what unit i summoned on the textlabel that says summoned and it doesnt take any money away. And it doesnt put the units textlabel in the inventory.
Are you really sure there is nothing in the output? If there are not, then try printing on every thing that you think isn’t working, or printing almost everywhere
Not even i know what does that mean lol, observablevalue undefined, huh? Well that happened with me too… today tho… with my ai script… Anyways, let’s get back to your issue, i’m not gonna put MY issue here.
Wow, my AI issue was like, 6 days or smth, and i haven’t fixed it yet, now you… you taked weeks? Now that’s what i call “Not giving up”, great, we need to fix it i’m gonna to stop saying about my AI script, i just need help on this, like i broke my head for days, i have tried my best… ok i’m gonna help you now
Well you know the summoned label the labed that says summoned its not showing the right text it should say “You have summoned” and then units name.
I might have missed it, but I don’t see in the server script you doing the FireClient.
I do not know how any of it is setup but somewhere you need to fire it back to the client. I only see it making it to the server. If you did a print(“Client Fired”) in your onclientevent you probably wont see it. But if you put something in your server script you probably would see it. I think this is what iaheitorzito is saying. Prints tell us how far along our logic has made it. I put things like print(“Server Fired”) and then client fired etc.