I’m working on a turn-based RPG game and I decided to add a move confirming system incase the player didn’t want to do that move. However in my script, When the move is confirmed. It prints out all the previous moves I didn’t want to do. So if I clicked health potion and didn’t want to choose that and chose to use a hammer. It would print out the health-potion and the hammer. Thinking I used both of them.
my script may be quite messy and confusing, and improvement suggestions are welcome too.
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid") or Character:FindFirstChildOfClass("Humanoid")
local PlayerData = Player:WaitForChild("PlayerStatistics")
local PlayerStats = PlayerData:WaitForChild("Statistics")
local Camera = workspace.CurrentCamera
local CurrentArena = workspace:WaitForChild("CurrentArena")
local Folder_Assets = ReplicatedStorage:WaitForChild("Assets")
local Folder_Remotes = Folder_Assets:WaitForChild("Remotes")
local Folder_Models = Folder_Assets:WaitForChild("Models")
local Folder_Items = Folder_Models:WaitForChild("Items")
local Folder_Weapons = Folder_Models:WaitForChild("Weapons")
local SoundTrack = SoundService.SoundTrack
local GUI = script.Parent
local IntroFrame = GUI:WaitForChild("Intro")
local ActionFrame = GUI:WaitForChild("Actions")
--
local Dark1 = IntroFrame:WaitForChild("Darken1")
local Dark2 = IntroFrame:WaitForChild("Darken2")
local Icon = IntroFrame:WaitForChild("Icon")
--
--
local TurnLabel = ActionFrame:WaitForChild("CurrentTurn")
local TurnTL = TurnLabel:WaitForChild("Team")
local ActInfo = ActionFrame:WaitForChild("Info")
local PlayerFrame = ActInfo:WaitForChild("PlayerFrame")
local EnemyFrame = ActInfo:WaitForChild("EnemyFrame")
local PlayerHP = PlayerFrame:WaitForChild("HP")
local EnemyHP = EnemyFrame:WaitForChild("HP")
local Moves = ActionFrame:WaitForChild("Moves")
local ListOfMoves = Moves:WaitForChild("List")
local TypeOfMoves = Moves:WaitForChild("Types")
local ConfirmMove = ActionFrame:WaitForChild("ConfirmMove")
local WeaponHelp = Moves:WaitForChild("WeaponInfo")
local ItemHelp = Moves:WaitForChild("ItemInfo")
local WeaponsBtn = TypeOfMoves:WaitForChild("Weapons")
local ItemsBtn = TypeOfMoves:WaitForChild("Items")
--
local FastIntroInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut)
local IntroInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut)
local LongIntroInfo = TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.InOut)
local ActionInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local CurrentTurn = "Players"
local MoveChosen = false
local function ClearStuff()
for _, UI in pairs(ListOfMoves:GetChildren()) do
if not UI:IsA("UIListLayout") then
UI:Destroy()
end
end
end
local function LoadStuff(Type)
local FolderOfThings = PlayerData:WaitForChild(Type)
ClearStuff()
for _, Thing in pairs(FolderOfThings:GetChildren()) do
if Type == "Items" then
local Template = script.ItemTemplate:Clone()
Template.Parent = ListOfMoves
Template.Item.Text = Thing.Name
local PhysicalItem = Folder_Items:WaitForChild(Thing.Name)
if PhysicalItem then
local HealthValue = PhysicalItem:WaitForChild("Heal")
local UsesValue = PhysicalItem:WaitForChild("Uses")
Template.Uses.Text = UsesValue.Value
Template.Stat.Text = HealthValue.Value
end
Template.Item.Activated:Connect(function()
if not MoveChosen then
MoveChosen = true
TweenService:Create(ConfirmMove, IntroInfo, {Position = UDim2.new(0.3, 0,0.2, 0)}):Play()
Moves.Blocker.Visible = true
TweenService:Create(Moves.Blocker, FastIntroInfo, {TextTransparency = 0.2}):Play()
ConfirmMove.Confirm.Activated:Connect(function()
MoveChosen = true
TweenService:Create(Moves, ActionInfo, {Position = UDim2.new(-1, 0,0.6, 0)}):Play()
TweenService:Create(ConfirmMove, IntroInfo, {Position = UDim2.new(-1, 0,0.2, 0)}):Play()
Folder_Remotes.CastMove:FireServer("Item", Thing.Name)
end)
ConfirmMove.Cancel.Activated:Connect(function()
MoveChosen = false
Moves.Blocker.Visible = false
TweenService:Create(Moves.Blocker, FastIntroInfo, {TextTransparency = 1}):Play()
TweenService:Create(ConfirmMove, IntroInfo, {Position = UDim2.new(-1, 0,0.2, 0)}):Play()
end)
end
end)
elseif Type == "Weapons" then
local Template = script.WeaponTemplate:Clone()
Template.Parent = ListOfMoves
Template.Item.Text = Thing.Name
local PhysicalWeapon = Folder_Weapons:WaitForChild(Thing.Name)
if PhysicalWeapon then
local DamageValue = PhysicalWeapon:WaitForChild("Damage")
local DurabilityValue = PhysicalWeapon:WaitForChild("Durability")
Template.Durability.Text = DurabilityValue.Value
Template.Damage.Text = DamageValue.Value
end
Template.Item.Activated:Connect(function()
if not MoveChosen then
MoveChosen = true
TweenService:Create(ConfirmMove, IntroInfo, {Position = UDim2.new(0.3, 0,0.2, 0)}):Play()
Moves.Blocker.Visible = true
TweenService:Create(Moves.Blocker, FastIntroInfo, {TextTransparency = 0.2}):Play()
ConfirmMove.Confirm.Activated:Connect(function()
MoveChosen = true
TweenService:Create(Moves, ActionInfo, {Position = UDim2.new(-1, 0,0.6, 0)}):Play()
TweenService:Create(ConfirmMove, IntroInfo, {Position = UDim2.new(-1, 0,0.2, 0)}):Play()
Folder_Remotes.CastMove:FireServer("Attack", Thing.Name)
end)
ConfirmMove.Cancel.Activated:Connect(function()
Moves.Blocker.Visible = false
MoveChosen = false
TweenService:Create(Moves.Blocker, FastIntroInfo, {TextTransparency = 1}):Play()
TweenService:Create(ConfirmMove, IntroInfo, {Position = UDim2.new(-1, 0,0.2, 0)}):Play()
end)
end
end)
end
end
end
local function StartIntro(IconImage, Music)
Icon.Image = "rbxassetid://" .. IconImage
local Music = SoundTrack:FindFirstChild(Music)
script.WooshIn:Play()
TweenService:Create(IntroFrame, LongIntroInfo, {BackgroundTransparency = 0}):Play()
TweenService:Create(Icon, FastIntroInfo, {Size = UDim2.new(0.5, 0,0.7, 0), Rotation = -4, ImageTransparency = 0}):Play()
TweenService:Create(Dark1, IntroInfo, {Position = UDim2.new(-0.1,0,0.5,0)}):Play()
TweenService:Create(Dark2, IntroInfo, {Position = UDim2.new(1.1,0,0.5,0)}):Play()
Music.Playing = true
TweenService:Create(Music, TweenInfo.new(1), {Volume = 0.65}):Play()
task.wait(1.75)
script.WooshOut:Play()
TweenService:Create(IntroFrame, FastIntroInfo, {BackgroundTransparency = 1}):Play()
TweenService:Create(Icon, LongIntroInfo, {Size = UDim2.new(0, 0,0, 0), Rotation = 5, ImageTransparency = 1}):Play()
TweenService:Create(Dark1, FastIntroInfo, {Position = UDim2.new(-2,0,0.5,0)}):Play()
TweenService:Create(Dark2, FastIntroInfo, {Position = UDim2.new(2,0,0.5,0)}):Play()
end
Folder_Remotes.StartBattle.OnClientEvent:Connect(function(Image, Music, Stat, NPC_Name)
StartIntro(Image, Music)
local NPC_Stats = require(Stat)
local NPC = Folder_Assets.Models.Characters:FindFirstChild(NPC_Name)
local Arena = CurrentArena:FindFirstChildOfClass("Folder")
local ArenaCAM = Arena:WaitForChild("A_Cam")
local PlayerCAM = Arena:WaitForChild("P_Cam")
local EnemyCAM = Arena:WaitForChild("E_Cam")
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = ArenaCAM.CFrame
task.wait(1)
TweenService:Create(ActInfo, ActionInfo, {Position = UDim2.new(0.5,0,0.85, 0)}):Play()
PlayerFrame.PName.Text = Player.DisplayName
PlayerFrame.Level.Text = "LVL . " .. PlayerStats.LVL.Value
PlayerHP.Value.Text = math.floor(Humanoid.Health) .. "/" .. Humanoid.MaxHealth
PlayerHP.Current.Size = UDim2.new(Humanoid.Health / Humanoid.MaxHealth,0,1,0)
--
EnemyFrame.EName.Text = NPC_Stats.NPC_Name
EnemyFrame.Level.Text = "LVL . " .. NPC_Stats.LVL
EnemyHP.Value.Text = math.floor(NPC.Humanoid.Health) .. "/" .. NPC.Humanoid.MaxHealth
EnemyHP.Current.Size = UDim2.new(NPC.Humanoid.Health / NPC.Humanoid.MaxHealth,0,1,0)
task.spawn(function()
TurnTL.Text = "It's your turn!"
TurnLabel.TypeOfAlert.Text = "NOTIFICATION"
script.Notification:Play()
TweenService:Create(TurnLabel, ActionInfo, {Position = UDim2.new(0, 0,0.3, 0)}):Play()
TweenService:Create(Camera, ActionInfo, {CFrame = PlayerCAM.CFrame}):Play()
task.wait(1.75)
TweenService:Create(TurnLabel, ActionInfo, {Position = UDim2.new(-1, 0,0.3, 0)}):Play()
end)
task.wait(1)
TweenService:Create(Moves, LongIntroInfo, {Position = UDim2.new(0.26, 0,0.6, 0)}):Play()
ItemsBtn.Activated:Connect(function()
WeaponHelp.Visible = false
ItemHelp.Visible = true
LoadStuff("Items")
end)
WeaponsBtn.Activated:Connect(function()
WeaponHelp.Visible = true
ItemHelp.Visible = false
LoadStuff("Weapons")
end)
end)
NEVERMIND I FIXED IT! I needed a debounce added in the server!