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
You just need to have the touched code and the debounce code if this is a bullet, nothing else. The bullet should only detect if something was a shield or not.
If you need to get the player, just use GetPlayerFromCharacter, a method of the players service, on the Parent of hit and do stuff with that
You use GetPlayerFromCharacter as I mentioned to get the player via hit.Parent, it may return nil if there was no player with that character, so use an if statement to check if what was hit was a character and if not, do nothing.
The article should hae an example of the use of it
Another way you could achieve this is by creating a bool value that detects if the shield is equipped, and if it is, then the player would take no damage(modify the damage script in the gun).
That function does not return a player and just waits for a player to join, also it only works once.
You’ll need to connect a PlayerAdded function to get your player.