Hi, so i have 4 text buttons and in this script im changing the text but when i change the text, all the text buttons have the same text and name. But im trying to make it so each textbutton’s text is each one of the attack names from the moveset folder
Script:
for i, v in pairs(script.Parent.Parent.encounterGui.Options:GetChildren()) do
if v:IsA("TextButton") then
for i, attacks in pairs(clonedAlumian.MoveSets:GetChildren()) do
v.Text = attacks.Name
print(attacks)
end
end
end
Well if you were to try to change a text with a nil value, and try to use .Name with a nil value it will print and error. The only possibility is that the script isn’t reaching the line that tells it to change the text.
You should also try defining “attacks” while you’re at it.
the thing is it looks like the script got to that line but although when the loop finds one attack it seems to change every textbutton’s text to that text. Wouldn’t i need a if statement or something?
Well I need to see if anything is interfering, and most importantly I need to see the context of the script and what all the variables are. Just paste the whole thing in here that’s all, no need to worry if your script is bad.
local player = game.Players.LocalPlayer
local RP = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
function createBattleTemp(petName)
local petModel = RP:WaitForChild("Pets"):FindFirstChild(petName, true)
local temp = RP:WaitForChild("Templates").Template
local battleFrameInv = script.Parent.BattleInv
if petModel ~= nil then
local cloned = petModel:Clone()
cloned:SetPrimaryPartCFrame(CFrame.new(0,0,0))
local clonedTemp = temp:Clone()
clonedTemp.Parent = battleFrameInv
clonedTemp.Visible = true
clonedTemp.Name = petName
local viewPort = clonedTemp.ViewportFrame
cloned.Parent = viewPort
local viewPortCamera = Instance.new("Camera")
viewPortCamera.Parent = viewPort
viewPort.CurrentCamera = viewPortCamera
clonedTemp.PetName.Text = clonedTemp.Name
game:GetService("RunService").RenderStepped:Connect(function()
local distance_Away = 4
viewPortCamera.CFrame = cloned.PrimaryPart.CFrame * CFrame.new(0, 0, -distance_Away) * CFrame.Angles(0, math.pi, 0)
end)
end
end
local tweenInfo = TweenInfo.new(
.25,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
local connection
RP.Bindables.ActivateBattle.Event:Connect(function()
for i, v in pairs(player:WaitForChild("Pets"):GetChildren()) do
print(v.Name)
createBattleTemp(v.Name)
end
for i, v in pairs(script.Parent.BattleInv:GetChildren()) do
if v:IsA("ImageButton") then
v.MouseButton1Click:Connect(function()
local alumianName = v.Name
script.Parent.BattleInv.Visible = false
for i, actualChar in pairs(workspace:GetChildren()) do
if string.find(actualChar.Name, " 2") then
local loadedAnim = actualChar.Humanoid.Animator:LoadAnimation(script.Animation)
local ball = RP:WaitForChild("AlumianBall")
local clonedBall = ball:Clone()
clonedBall.Parent = actualChar
clonedBall.CFrame = actualChar["Left Arm"].CFrame * CFrame.new(0,-1.5,0)
local weldC = Instance.new("WeldConstraint")
weldC.Part0 = actualChar["Left Arm"]
weldC.Part1 = clonedBall
weldC.Parent = actualChar
loadedAnim:Play()
loadedAnim.KeyframeReached:Connect(function(keyframe)
weldC:Destroy()
clonedBall.Anchored = true
local tween = TS:Create(clonedBall, tweenInfo, {CFrame = workspace.BattleStage.Position1.CFrame})
tween:Play()
tween.Completed:Connect(function()
local effect = RP:WaitForChild("Effect")
effect.Parent = workspace
effect.CFrame = clonedBall.CFrame * CFrame.new(0,2,0)
TS:Create(effect, tweenInfo, {Size = Vector3.new(12,12,12), Transparency = 1}):Play()
local alumian = RP:WaitForChild("Pets"):FindFirstChild(alumianName, true)
if alumian then
clonedBall:Destroy()
local clonedAlumian = alumian:Clone()
clonedAlumian.Parent = workspace
clonedAlumian.PrimaryPart.CFrame = workspace.BattleStage.Position1.CFrame * CFrame.new(0,2,0)
connection = game:GetService("RunService").RenderStepped:Connect(function(step)
if not clonedAlumian:FindFirstChild("NotFly") then
clonedAlumian:SetPrimaryPartCFrame(clonedAlumian.PrimaryPart.CFrame:Lerp(clonedAlumian.PrimaryPart.CFrame * CFrame.new(0, 0.33 * math.sin(tick(), 1.5), 0), step))
else
end
end)
TS:Create(workspace.CurrentCamera, tweenInfo, {CFrame = workspace.CameraPart2.CFrame}):Play()
local isBattling = true
script.Parent.Parent.encounterGui.Options.Visible = true
for i, v in pairs(script.Parent.Parent.encounterGui.Options:GetChildren()) do
if v:IsA("TextButton") then
for i, attacks in pairs(clonedAlumian.MoveSets:GetChildren()) do
print(attacks)
end
end
end
end
end)
end)
end
end
end)
end
end
end)
Oh wait I forgot that the definition of attacks was right there. Maybe you should rename it to “attack” tho since it’s focusing on just one attack out of the list. Anyways your script should be working, so I’m stumped.
The reason it is giving all the text buttons the same label is because when naming you are looping through each button and changing the name to the last element in that returned array.
local t =clonedAlumian.MoveSets:GetChildren() ;
for i, v in pairs(script.Parent.Parent.encounterGui.Options:GetChildren()) do
if v:IsA("TextButton") then
for _ , L in pairs(t) do
v.Name = L.Name
table.remove(t,index)
break
end
end
A for loop loops through an array and sets the V value to the index of the array, so the original script was not setting the name to an array, I’m pretty sure it would error if you attempted to do that.