I’m creating a Tower Defense game. I was creating a gacha system based on the AlvinBlox video - https://youtu.be/wip3VN-LUA0 ?feature=shared
At some point, he started creating an animation of the egg opening on 3d models.
I just need an already created gui frame to appear along with a random tower.
Below are examples with single opening and decimal.
This is my code with the output of a random tower:
local gui = game.StarterGui.ShopGui
local Open1x = gui.MainShopFrame.ShopFrame.Action.OpenButton1X
local Open10x = gui.MainShopFrame.ShopFrame.Action.OpenButton10X
local towerModule = require(game.ServerScriptService:WaitForChild("TowerModule"))
game.ReplicatedStorage.RemoteEvents.Open1x.OnServerEvent:Connect(function(player, tower)
if player.leaderstats.Coins.Value >= Open1x.Config.Price.Value then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - Open1x.Config.Price.Value
local tower = towerModule.chooseRandomTower()
print(tower.Name.." Selected")
end
end)
game.ReplicatedStorage.RemoteEvents.Open10x.OnServerEvent:Connect(function(player, tower)
if player.leaderstats.Coins.Value >= Open10x.Config.Price.Value then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - Open10x.Config.Price.Value
local tower = towerModule.chooseRandomTower()
print(tower.Name.." Selected")
end
end)
I created frames with images of towers. I want the corresponding frame with it to be displayed after receiving the random tower. And no, gui is not showing up yet
From what I saw in the video the output displayed the name of the tower. So I’m assuming the name of the tower is stored as variable then all you need to do is loop through the folder with the GUIs and use the function FindFirstChild with the variable as the perimeters. (Note: when you use the FindFirstChild function you need to put it in a variable) finally take the variable with the the findfirstchild function in it and change the GUI to enabled since the variable with findfirstchild will return an frame in your folder
Fire a remote from server to client with the name of the tower:
game.ReplicatedStorage.RemoteEvents.Open1x.OnServerEvent:Connect(function(player, tower)
if player.leaderstats.Coins.Value >= Open1x.Config.Price.Value then
player.leaderstats.Coins.Value -= Open1x.Config.Price.Value
local tower = towerModule.chooseRandomTower()
-- fire here a remove event with the name
game.ReplicatedStorage.RemoteEvents["YOUR EVENT"]:FireClient(player, tower.Name)
print(tower.Name.." Selected")
end
end)
Client:
Make a folder in your GUI, store all your images there and make the one needed visible. I cloned the one needed because it’s easier than looping thru many Images with for i loops.
game.ReplicatedStorage.RemoteEvents["YOUR EVENT"].OnClientEvent:Connect(function(TowerName)
--- Make a folder and store all the imagines there
local Folder = "..."
local ShowImage = Folder[TowerName]:Clone()
ShowImage.Visible = true
task.wait(3) -- time until it goes away
ShowImage:Destroy()
end)