Hi, i was trying to make a tycoon game (with small buildings, micro soldiers etc.)
and i wanted to make a build upgrade system (farmlevel1, farmlevel2)
but text button in billboard gui fires the event 2 times and destroys the model before cloning for some reason. I tried to move the upgrade from replicated storage and clone it then place it to the replicated storage, but it will probably create problems in multiplayer.
--[[
____ ___ .__ ________
| | \___________ ____ _____ | | \______ \ _______ __
______ ______ ______ | | / \_ __ \_/ __ \\__ \ | | | | \_/ __ \ \/ / ______ ______ ______
/_____/ /_____/ /_____/ | | / | \ | \/\ ___/ / __ \| |__ | ` \ ___/\ / /_____/ /_____/ /_____/
|______/|___| /__| \___ >____ /____/ /_______ /\___ >\_/
\/ \/ \/ \/ \/
--]]
local function onClick()
print("working")
local player = game:GetService("Players").LocalPlayer
if player then
local chr = player.Character or player.CharacterAdded
if chr then
if chr:WaitForChild("Humanoid") and chr:WaitForChild("Humanoid").Health > 0 then
local rs = game:GetService("ReplicatedStorage")
local levels = rs.Structures:WaitForChild(script.Parent.Parent.Type.Value):GetChildren()
for i, nextLevel in pairs(levels)do
if tonumber(nextLevel.Name) - script.Parent.Parent.Level.Value == 1 then
print(nextLevel.Name)
--current vars--
local crrntLevel = script.Parent.Parent.Adornee.Parent.Parent
local crrntModel = crrntLevel:FindFirstChild(tostring(script.Parent.Parent.Level.Value))
--change levels--
if crrntModel then
script.Parent.Parent.Level.Value = script.Parent.Parent.Level.Value + 1
local NextLevel = nextLevel:Clone()
NextLevel:SetPrimaryPartCFrame(crrntModel.PrimaryPart.CFrame)
script.Parent.Parent.Adornee = NextLevel.PrimaryPart
crrntModel:Destroy()
end
end
end
end
end
end
end
script.Parent.MouseButton1Click:Connect(onClick)