#fucking script aint working
1 messages · Page 1 of 1 (latest)
local db = false
game.ReplicatedStorage.RemoteEvents.Weapons.ExplodeGrenade.OnServerEvent:Connect(function(plr, part)
local ok = Instance.new("Explosion")
ok.Position = part.Position
ok.Parent = workspace
ok.BlastRadius = 500000
ok.BlastPressure = 0
ok.DestroyJointRadiusPercent = 0
part:Destroy()
print(ok.Name)
ok.Hit:Connect(function(hitPart, distance)
if db then return end
db = true
local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and humanoid.Health > 0 then
print("Hit", humanoid.Parent.Name, "at distance", distance)
local maxDamage = 80
local maxRadius = 30
local damage = 0
if distance <= maxRadius then
damage = math.floor(maxDamage * (1 - distance / maxRadius))
damage = math.max(damage, 0)
end
if damage > 0 then
humanoid:TakeDamage(damage)
end
end
task.wait(2)
db = false
end)
end)
--ok
What prints print, and which ones don't?
sometimes the distance thingy doesnt print but sometimes it does
lemme test again
one sec
ok yea doesnt print anything now
well if were talking abt the ok.Hit part but the others print
And just to be sure, you are letting the db turn back to false in between tests right (else we'll be looking for some issue while it's just the first if statement messing it up for those times)
Well yes, but in the tests you are actually waiting for the 2 seconds in between trying to check if it prints, right?
i have another script that that has a cooldown so after clicking once u got a 45 sec cool down so i gotta rerun the game
also i think i know what the problem is
Alrighty, then it's this line local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChildWhichIsA("Humanoid")
could be that i gotta put the ok.Hit:Connect(function() before it gets put in the workspace
lemme print Humanoid to make sure
It could hit an accessory, then it will have activated the db, while hitPart.Parent = the accessory
(or well, the part inside an accessory, as accessories are technically just data)
ok yea i tested it and u were right bc its not finding a humanoid
** You are now Level 2! **
I would just replace the line with
local humanoid = hitPart.Parent.Humanoid or hitPart.Parent.Parent.Humanoid
Just make sure that it doesn't error, I doubt that hitPart.Parent = nil (as that would mean that it hits some nilinstance somehow), yet better safe than sorry
ok i got it working but had to go with a whole different method