I was working on a script for an ability, and I encountered an issue. In the script below, you will see I used script.Parent.Touched:Connect(function(t), however it didn't work. I tried the same exact script on a normal brick in workspace to see if I was crazy, and it worked. Here is my script:
--This is the damage script inside the damage part (script is disabled until activated in next script) if it helps, this is a server script. script.Parent.Touched:Connect(function(t) if t.Parent:FindFirstChild("Humanoid") then t.Parent.Humanoid:TakeDamage(15) end end)
script 2:
--Variables may be confusing, so I will give context. (if it helps, this is a server script in serverscriptservice) local tchfx = game.ReplicatedStorage:WaitForChild("ThunderCharge") --The damage part local Elfx = game.ReplicatedStorage:WaitForChild("ElectricityFx") --This is just an effect for it tch.OnServerEvent:Connect(function(p) local c = p.Character local hrp = c:FindFirstChild("HumanoidRootPart") local tchfxc = tchfx:Clone() local ElfxC = Elfx:Clone() tchfxc.Parent = workspace -Putting damage part in workspace hrp.Position = Vector3.new(hrp.Position.X,hrp.Position.Y * 2,hrp.Position.Z) --Putting tchfxc.Position = Vector3.new(hrp.Position.X,hrp.Position.Y,hrp.Position.Z) --Putting character higher in air damage part where character is hrp.Anchored = true --Making it so character doesn't move wait(.25) ElfxC.Position = Vector3.new(hrp.Position.X,hrp.Position.Y,hrp.Position.Z) --Putting effects where character is ElfxC.Parent = workspace --Putting effects in workspace ElfxC.Script.Disabled = false --Enablingscript inside of effect tchfxc.Dmg.Disabled = false --Enabling damage script, which should make everything it touches do some damage end)
For even more context, Second script is a function called through client by pressing a key (that is working nicely, so that isn't part of the issue. The script DOES enable when the script runs, The parts do show up at the characters humanoidrootpart, But for some reason it does not damage.
I found a solution that works for me
local player = game.Players.LocalPlayer local debounce = false --the debounce is for a cooldown script.Parent.Touched:Connect(function(hit) if not debounce then debounce = true local character = hit.Parent local Humanoid = character:FindFirstChildWhichIsA("Humanoid") if Humanoid then Humanoid.Health = Humanoid.Health-15 --change the number to how much health you want the player lose end wait(1) --change the number to how many seconds you want before it hurts you again debounce = false end end)
This is a server script inside of the part that takes the damage.