You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Hello i want to create a tycoon with merging similar to this game Zombie Merge Tycoon - Roblox and i wrote the script below that merges three avatars and if there’s like 5 it will merge 3 and keep the 2 old avatars it’s a normal script (not local script) and is located inside of a part in the workspace -
What is the issue? Include screenshots / videos if possible!
The problem is that the script works perfectly but the code inside the function MultipleOfThree (that let the script know how many avatars he needs to destroy) doesn’t work like if it was ignored -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to replace the repeat loop with a while loop but didn’t work and tried to move the function inside the .Touched event
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--Avatars
local NormalAvatar = 0
local BlueAvatar = 0
--Script
local Button = script.Parent
local debounce = false
local Positions = game.Workspace.Tycoons.Tycoon1.Positions:GetChildren()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local function MultipleOfThree(Avatar) --Makes a numbre a multiple of three
if Avatar > 3 and Avatar % 3 ~= 0 then
repeat Avatar -= 1 until Avatar % 3 == 0
end
end
Button.Touched:Connect(function(hit)
if hit.Parent:WaitForChild("Humanoid") and debounce == false then
debounce = true
for i , v in pairs(game.Workspace.Tycoons.Tycoon1.Avatars:GetChildren()) do
if v.Name == "NormalAvatar" then
NormalAvatar += 1
elseif v.Name == "BlueAvatar" then
BlueAvatar += 1
end
end
MultipleOfThree(NormalAvatar)
MultipleOfThree(BlueAvatar)
print(NormalAvatar)
print(BlueAvatar)
if NormalAvatar >= 3 then
for i , v in pairs(game.Workspace.Tycoons.Tycoon1.Avatars:GetChildren()) do
if NormalAvatar == 0 then continue end
if v.Name == "NormalAvatar" then
v:Destroy()
NormalAvatar -= 1
if i % 3 == 0 then
local BlueAvatar = ReplicatedStorage.Avatars.BlueAvatar:Clone()
BlueAvatar.Parent = game.Workspace.Tycoons.Tycoon1.Avatars
for i ,v in pairs(BlueAvatar:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") then
if v.Name ~= "HumanoidRootPart" then
v.Transparency = 1
local Tween = TweenService:Create(v,TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Transparency = 0 })
Tween:Play()
end
end
end
end
end
end
elseif BlueAvatar >= 3 then
for i , v in pairs(game.Workspace.Tycoons.Tycoon1.Avatars:GetChildren()) do
if BlueAvatar == 0 then continue end
if v.Name == "BlueAvatar" then
v:Destroy()
BlueAvatar -= 1
if i % 3 == 0 then
local FireAvatar = ReplicatedStorage.Avatars.FireAvatar:Clone()
FireAvatar.Parent = game.Workspace.Tycoons.Tycoon1.Avatars
for i ,v in pairs(FireAvatar:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") then
if v.Name ~= "HumanoidRootPart" then
v.Transparency = 1
local Tween = TweenService:Create(v,TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Transparency = 0 })
Tween:Play()
end
end
end
end
end
end
end
for i , v in pairs(game.Workspace.Tycoons.Tycoon1.Avatars:GetChildren()) do
v.HumanoidRootPart.CFrame = Positions[i].CFrame
end
NormalAvatar = 0
BlueAvatar = 0
wait(1)
debounce = false
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.