local shield = script.Parent
local player = game.Players.PlayerAdded:Wait()
shield.Touched:Connect(function(hit)
if hit.Parent == hit.Parent:FindFirstChild("Bullet") then
player.BulletHit.Value = player.BulletHit.Value - 1
repeat wait() until player.BulletHit.Value == 0
end
if player.BulletHit.Value == 0 then
shield:Destroy()
end
end)
Im getting no errors but it’s not doing anything, why?
What’s with the game.Players.PlayerAdded:Wait()? What is that trying to do? It’s jsut going to wait for a player to be added before continuing
if hit.Parent == hit.Parent:FindFirstChild("Bullet") then will probably not be met since they’d not be equal since they’re different instances in this case
Final question, what are you even trying to do in the first place? I’m not understanding the code that well
so im trying to make a shield that protects the player, but im not sure how to make it so the player doesn’t take any damage while the shield is on. I figured out the problem to this just now, i put this script into serverscriptservice and changed a few things.
How is the shield set up exactly? Is it a part of the player’s character? It could be an external part that the player is inside off, and then jsut add a check in your weapons that check if what is it is a shield, and if it was, just hurt the shield.
If you have multiple checks i nyour weapons, just make the shield check have priority
Then I recommend in your weapon checks, check if the name of the part hit was called “Shield”, and if it was, make it decrease the value in the shield part, And in a script i nthe part, make it listen for changes to the Value’s value, and if the value ever goes 0 or below, destroy the shield
I think again, you can make whatever is trying to deal damage check if the name of the part that’s being hit is the same name as the name of the shield part if you only have one part as the shield, otherwise, check the name of the parent of the part is equal to the name of the shield. If you give the shield check priority before others, it’ll prevent the humanoid from eing
damaged
Example
if hit.Name == "Shield" then
--decrease value in shield part
elseif hit.Parent:FindFirstChildOfClass("Humanoid") then
--Damage humanoid
end
local player = game.Players.PlayerAdded:Wait()
local debounce = false
local player = game.Players.PlayerAdded:Wait()
local char = player.Character or player.Character:Wait()
script.Parent.Touched:Connect(function(hit)
if hit.Name == "Shield" then
player.BulletHit.Value -= 1
elseif hit.Parent:FindFirstChildOfClass("Humanoid") then
char.Humanoid = char.Humanoid - 10
end
end)
No…What is this script even for the shield? That’s not how it should be done. The weapons you have currently/enemies, those should be the ones that check if what they hit is a shield, not the shield itself, because they can still damage you without the check
Oh, then another question, why is the bullet checking for players? It doesn’t have to do that, it should only check what it has hit. Also, you should debounce this since it’ll do continous damage to the shield and humanoid