Hi! So I tweened a brick so when it comes at you, it kills you. But, I want to make an exception to this: if a part is parented to workspace, it will not do so (will not kill you.) Does anyone think they can help? Thanks.
Here is the script I have:
local hb = game.ReplicatedStorage.HB
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if hb.Parent == game.Workspace then return false end
hit.Parent.Humanoid.Health = 0
end
end)
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if hb.Parent ~= workspace then
hit.Parent.Humanoid.Health = 0
end
end
end)
Or
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if hb.Parent == workspace then return end
hit.Parent.Humanoid.Health = 0
end
end)
What is the HB thing inside of ReplicatedStorage? Also for the check to not do anything if the part is a child of workspace, you can just do return end rather than return false end. Also you can use workspace instead of game.Workspace but that’s just personal preference
Wait hang on, I dont think the exception you did will never become true, since the parent of hb is ReliplicatedStorage, unless the parent is changed from another script
Then if nothing changes its parent then I dont think that condition will ever become true, since the parent is always going to be ReplicatedStorage, if so, I dont think you need that condition for now, you can comment it out for now till something changes the parent
Here’s how I would do the code
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent -- Made a variable since I'm using hit.Parent more than once, personal preference
if game.Players:GetPlayerFromCharacter(char) then
--if hb.Parent == workspace then return end
char.Humanoid.Health = 0
end
end)