What do you want to achieve? Keep it simple and clear!
I’m trying to create a script which prevents team/self killing, thus far I have been unable to do so using methods which logically and previously have worked for me
What is the issue? Include screenshots / videos if possible!
Despite thousands upon thousands of print tests throughout my script to try and find said issue, I can’t find a single instance where the logic doesn’t work and yet the code doesn’t work
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
-- e.g. The most basic of basic, and most commonly known to be functional, doesn't function properly (TargetPlayer.Team ~= Player.Team then do damage)
--[[ Variables Already Defined:
Player: The player firing the rocket
Damage: The expected Damage
ExplosionPosition: Where the Explosion is from
BlastRadius: Radius of the explosion
CosmeticBullet: a Visual Representation of a Bullet
]]
NearbyParts = game.Workspace:GetPartBoundsInRadius(ExplosionPosition, BlastRadius)
-- Keeps it from hitting itself
local ExplosionParams = RaycastParams.new()
ExplosionParams.FilterType = Enum.RaycastFilterType.Blacklist
ExplosionParams.FilterDescendantsInstances = {CosmeticBullet, Player.Character}
-- Proper Explosions, without physics lag
for i, v in pairs(NearbyParts) do
if v:FindFirstAncestorWhichIsA("Model") and v:FindFirstAncestorWhichIsA("Model"):FindFirstChildWhichIsA("Humanoid") then
local Direction = v.Position - ExplosionPosition
local Raycast = game.Workspace:Raycast(ExplosionPosition, Direction, ExplosionParams)
local Char = v:FindFirstAncestorWhichIsA("Model")
local Humanoid = Char:FindFirstChildWhichIsA("Humanoid")
if Raycast and Raycast.Instance == v or Raycast and Raycast.Instance.Parent == v.Parent then
local TargetPlayer = Players:GetPlayerFromCharacter(Char)
if TargetPlayer.Team ~= Player.Team then
table.insert(ExplosionParams.FilterDescendantsInstances, Char)
Humanoid:TakeDamage(Damage)
end
end
end
end
Explosion.Hit:Connect(function(hit)
if hit.parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local h = hit.parent:FindFirstChild("Humanoid")
assert(h, "No humanoid found")
if player.Team ~= YOURTEAM then
hum:TakeDamage(dmg)
end
end
end)
I’m on mobile, there might be some errors. Hope this helps
Make sure that the Player and TargetPlayer variables are correctly assigned. You can add some print statements to print the values of these variables and make sure they are what you expect them to be.
Make sure that the Player and TargetPlayer variables have the correct Team value. You can add some print statements to print the values of these variables and make sure they are what you expect them to be.
Make sure that the Humanoid:TakeDamage(Damage) line is only being executed when the TargetPlayer is on a different team from the Player . You can add some print statements to print a message when this line is executed to make sure it is only being executed when you expect it to be.
Make sure that the TakeDamage function is actually causing the player to take damage. You can add some print statements to print the value of the Humanoid.Health property before and after the call to TakeDamage to make sure that the player’s health is actually decreasing.
Set Explosion.DestroyJointRadiusPercent to 0 for the explosion you are using. This will fix your issue. Nothing is wrong with your boolean logic, I think you were just looking in the wrong area.
Cut the ChatGPT. Nothing you’re saying makes any sense in the slightest and if people wanted help from the chatbot they would do it themselves. This is extremely harmful not only to the OP but for people looking for solutions in the future.
I’d like to mention that I have done print statements, and it was said I did, I solved the issue by doing a ridiculous workaround however earlier this morning and just got back to this
As for anyone wondering what I did, I ended up naming the projectile the same name as the player’s team when it’s first created/cloned. Needing to grab the team through the projectile’s name felt pretty ridiculous of a solution to have to do, but it works for now and I’m hoping to find a better solution soon.
Ty, but as I said above I’m not using roblox’s explosion system because it hits players beyond walls and I would have to do essentially the same system just differently
Unless there was a recent change to how their explosions work, I’m going to stick with what I currently have until I find a better or more efficient system
I’m glad you found a working solution, albeit a hacky one. As an alternative, you could try comparing the TeamColor of each player’s team. I’m unsure why comparing two identical instances yielded an incorrect result. I usually don’t like solving my problems without understanding what went wrong, because I might encounter a similar issue in the future and go through the same process. It’s just a time-wasting habit of mine, no need to take notes