Basically I want to find the index of how many shields there are. I want to find the method of getting the index. Basically, if a shield is there already, I don’t want to add another shield.
How are you storing your shield data so that you can find the answers to your question?
An array of instances like so?
local playerShields ={shield1,shield2}
Code would be necessary for further understanding.
Hi, yes, here’s the code(Note: this is a module script.):
local fight = {}
function fight.Shield(spacecraft)
local sphere = script:WaitForChild("Sphere"):Clone()
sphere.Parent = workspace
sphere.Position = spacecraft.Position
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(
.25,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
1,
false,
0
)
local goal = {
Size = Vector3.new(64.017, 64.017, 64.017)
}
local created = tweenservice:Create(sphere, info, goal)
created:Play()
end
return fight
Here’s the script that calls the module script(it’s a local script):
local module = require(workspace:WaitForChild("ComatSystem"))
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.R then
module.Shield(workspace:WaitForChild("SpaceCraft"))
end
end)
Right below this line you would put a if condition(if there is a shield already) return end that will stop the script from continuing your module looks like it’s being played client-side meaning other people wont see this shield appear
A Boolean value for the shield would be a simple way to see if its equipped/unequipped.
That’s what I don’t know what to do and that’s actually what I’m asking how to do it.
if workspace.SpaceCraft:WaitForChild("Sphere") then return end
this might work if the sphere is the shield. But you needa fix how the sheild will only appear on the client who called the function. then you need design a identify whos space craft is who. At the moment… looks like your system wont work for more than one player.
You can just edit your fight module
local fight = {
HasShield = false;
}
function fight.Shield(spacecraft)
if fight.HasShield then return end
fight.HasShield = true
local sphere = script:WaitForChild("Sphere"):Clone()
sphere.Parent = workspace
sphere.Position = spacecraft.Position
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(
.25,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
1,
false,
0
)
local goal = {
Size = Vector3.new(64.017, 64.017, 64.017)
}
local created = tweenservice:Create(sphere, info, goal)
created:Play()
end
return fight
Then where ever you remove it (if it’s a function in this module) you just set it back to false so you can add the shield in again.
But you will battle with bots so I don’t see a point. Also, the other place would know since every time they shoot their bullets towards their opponent, they’ll know there’s an invisible barrier. I’ll mention it in the description.
So it is single-player that is reassuring but…
Since it’s client-side for the other players, the barrier wouldn’t be applied, In your input detection function the client just pulls up their shield But… the server has no clue that player placed there shields up since no remote was fired so if you planned to have the shield negate damage you will need to create a remote to tell the server shields are up. Or the shields will be totally ignored ( meaning shields wont even be effective againest bots or players )
I’ve tried this with if not bool value and if bool value == false and it hasn’t worked.
Have you tried what I recommended? also to use that you would need boolvalue instances have you made those?
I have tried what you said and it either yielded or did not work, I tried using FindFirstChild just to be clear.
You have to know where you parent shield and just check if its there or not did anything appear in the output log.