I’m having trouble getting a Projectile to Detect if a player has that few seconds of immunity when they respawn. I have tried to check if the opposing player has a force field in their character, but nothing is happening.
if hit:IsA("ForceField") then
print("ug")
else
explosion.BlastPressure = 1
kills.Value = kills.Value + 1
rocket:Destroy()
end
You can get the player from the character, then check if there’s a force field inside of the player.
like this:
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if(player) then
if(player.Character:FindFirstChild("ForceField")) then
else
--Your code here
end
end
end)
Yes, thanks for telling me about it , I missed a bracket in the end. I am kinda used to write ifs with brackets. so I did not notice. It can be written without brackets, or with, it does really not matter
Some programming languages enforce the use of brackets after IF statements for their respective conditions. I think that trend has traversed into ROBLOX Lua.
Yeah, a lot of like minded programmers that use additional languages other than Lua seem to have this habit. Again I think it’s perfectly fine which method anyone uses, it’s all down to personal preference really.
Why? There’s only one force field… and it’s named force field, there aren’t any other parts named force field in there. Both ways do the same thing, so why instead?
It’s always better to find these instances by their ClassNames than their Names unless you absolutely need to find them via their names. You never know if the name is going to change (usually happens when you’re working with another developer) and it’s better for universality.
That’s true that names can change, but it’s also easy to solve, just change the name, and also, classes can also change, and new classes are being added to replace them as well sometimes I believe, just like services, a new one added, an old one get deprecated.
The difference is that one will most likely never change and that the other can be changed at any time. This is why finding things via their ClassNames is much, much more reliable.
What’s their interest to change names often and at any time? And also, aren’t services classes too? They get changed many times as well. For example, GamePassService and MarketplaceService. And I am sure many classes refer to the force field by it’s name, so why will they change it?
Depending on your use case, FindFirstChildWhichIsA, which will also account for inherited classes. Anything to do with class strictly checks the ClassName, IsA will run IsA and account for any instance’s superclasses. For example, ScreenGui IsA LayerCollector.
I think this conversation’s pretty off topic at this point anyway, just wanted to throw a quick tidbit. Mind moving to DMs? cc @LightningLion58