Hello!
Im trying to make an attack for my game, which is similar to LIMBO keys(basically its a bunch of parts shuffled around and you need to track which one it is) for my remake of it, im using points scattered through the area and when a part is going to be shuffled, its going to roll a random number, find the part named that number, checks for a object called “Occupied,” if Occupied isnt found it will clone a BoolValue called “Occupied,” tween to that part. If it does find it, it re-rolls and tries again. The issue im having is that its not checking if “Occupied” is found. Its just tweening to that part. Thank you for your assistance
--sorry this code is horrible with unused functions and stuff, ill remove them
local SpearAttack = {}
local TS = game:GetService("TweenService")
print("e")
local walls = game.Workspace.Wall
function SpearAttack.Attack(plr,turnNumber,pushforce, numberOfSpears)
local selected = 0
local Position = 0
local plrHasSelected = 1
local amountOfTurns = 15
local guessingTime = game.ReplicatedStorage.GuessTime
local rightAnswer = math.random(1,4)
game.ReplicatedStorage.LimboKey.Value = rightAnswer
local function roll()
selected = math.random(1,4)
if not workspace.LIMBO[tostring(selected)]:FindFirstChild("Occupied") then
selected = math.random(1,4)
end
end
local function movePart(v)
selected = math.random(1,4)
print("newvalue"..selected)
if not workspace.LIMBO[tostring(selected)]:FindFirstChild("Occupied") then
roll()
return
end
TS:Create(v, TweenInfo.new(0.3), {Position = workspace.LIMBO:FindFirstChild(selected).Position}):Play()
end
local keys = game.ReplicatedStorage.Attacks.Keys
for _,v in keys:GetDescendants() do
if v:IsA("BasePart") then
local hb = Instance.new("Part")
wait(0.05)
local v2 = v:Clone()
roll()
if not workspace.LIMBO:FindFirstChild(selected):FindFirstChild("Occupied") then
local e = game.ReplicatedStorage.Attacks.Occupied:Clone()
e.Parent = workspace.LIMBO[tostring(selected)]
v2.Parent = workspace.KeysAvaliable
v2.Position = workspace.LIMBO:FindFirstChild(selected).Position
else
roll()
local e = game.ReplicatedStorage.Attacks.Occupied:Clone()
e.Parent = workspace.LIMBO[tostring(selected)]
local v2 = v:Clone()
v2.Parent = workspace.KeysAvaliable
v2.Position = workspace.LIMBO:FindFirstChild(selected).Position
end
end
end
wait(0.7)
TS:Create(game.Workspace.KeysAvaliable[tostring(rightAnswer)], TweenInfo.new(0.3), {Color = Color3.new(0.333333, 0.666667, 0.498039)}):Play()
wait(0.3)
TS:Create(game.Workspace.KeysAvaliable[tostring(rightAnswer)], TweenInfo.new(0.3), {Color = Color3.new(1, 1, 1)}):Play()
for i = 1, amountOfTurns do
print("roll")
wait(0.31)
for _,v in workspace.LIMBO:GetDescendants() do
if v:IsA("BoolValue") or v.Name == "Occupied" then
v:Destroy()
end
end
for _,v in workspace.KeysAvaliable:GetDescendants() do
if not workspace.LIMBO[tostring(selected)]:FindFirstChild("Occupied") then
roll()
TS:Create(v, TweenInfo.new(0.3), {Position = workspace.LIMBO:FindFirstChild(selected).Position}):Play()
elseif workspace.LIMBO[tostring(selected)]:FindFirstChild("Occupied") == true then
print("found")
movePart(v)
end
end
end
wait(5)
guessingTime.Value = true
for _,v in pairs(workspace.KeysAvaliable:GetDescendants()) do
wait(2)
plrHasSelected += 1
game.ReplicatedStorage.SelectedKey.Value = plrHasSelected
TS:Create(game.Workspace.KeysAvaliable[tostring(plrHasSelected)], TweenInfo.new(0.3), {Color = Color3.new(0.333333, 0.666667, 1)}):Play()
TS:Create(game.Workspace.KeysAvaliable[tostring(plrHasSelected - 1)], TweenInfo.new(0.3), {Color = Color3.new(1, 1, 1)}):Play()
end
game.UserInputService.InputBegan:Connect(function(keycode)
print("RightShift-Inputed")
if keycode.KeyCode == Enum.KeyCode.RightShift then
if guessingTime == true then
print("Guessing time")
if plrHasSelected == rightAnswer then
print("You guessed right!")
else
game.Players.LocalPlayer.Value.CurrentHealth.Value -= 10
end
for _,v in pairs(workspace.KeysAvaliable:GetDescendants()) do
v:Destroy()
end
end
end
end)
end
return SpearAttack