Hello, Im trying to make it so that whenever a player kill’s another player, they have to get 2 more kills in 9 seconds, and they will be awarded something if they are successful.
Im getting this error though, and Im not sure how to fix it.
Error:
21:36:14.713 Touched is not a valid member of LocalScript "Workspace.Dummy.Streak" - Server - CheckDmg:9
21:36:14.713 Stack Begin - Studio
21:36:14.713 Script 'Workspace.Dummy.DamagedBy.CheckDmg', Line 9 - Studio - CheckDmg:9
21:36:14.713 Stack End - Studio
Script:
local damagedBy = script.Parent
local h = script.Parent.Parent:WaitForChild("Humanoid")
local hrp = h.Parent:WaitForChild("HumanoidRootPart")
h.HealthChanged:Connect(function()
for i, v in pairs(hrp.Parent:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Name == "Handle" then
damagedBy = hit.Parent.Parent.Name
end
end)
end
end)
21:52:40.015 Touched is not a valid member of StringValue "Workspace.Dummy.DamagedBy" - Server - CheckDmg:9
21:52:40.015 Stack Begin - Studio
21:52:40.015 Script 'Workspace.Dummy.DamagedBy.CheckDmg', Line 9 - Studio - CheckDmg:9
21:52:40.016 Stack End - Studio
local damagedBy = script.Parent
local h = script.Parent.Parent:WaitForChild("Humanoid")
local hrp = h.Parent:WaitForChild("HumanoidRootPart")
h.HealthChanged:Connect(function()
for i, v in pairs(hrp.Parent:GetChildren()) do
v.Touched:Connect(function(hit)
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Name == "Handle" then
damagedBy = hit.Parent.Parent.Name
end
end)
end
end)
end
end)
You need to add a if statment to check whether it is a BasePart as something like a LocalScript (as referred to in your error) does not have the .Touched property
Potential fix:
local damagedBy = script.Parent
local h = script.Parent.Parent:WaitForChild("Humanoid")
local hrp = h.Parent:WaitForChild("HumanoidRootPart")
h.HealthChanged:Connect(function()
for i, v in pairs(hrp.Parent:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Name == "Handle" then
damagedBy = hit.Parent.Parent.Name
end
end)
end
end
end)
This made it work, but now for some reason, after the 9 seconds, the print function doesn’t work.
Their aren’t any errors eathier.
local db = script.Parent:WaitForChild("DamagedBy")
local h = script.Parent:WaitForChild("Humanoid")
local selfKills = script:WaitForChild("Kills")
local BadgeService = game:GetService("BadgeService")
local Audio = Instance.new("Sound")
function dead()
local KilledBy = db
for i, v in pairs(game.Workspace:GetChildren()) do
if v.ClassName == "Model" then
if v.Name == KilledBy.Name then
local Kills = v:WaitForChild("Streak"):WaitForChild("Kills")
Kills += 1
end
end
end
end
if h.Health == 0 then
dead()
end
while true do
task.wait()
if selfKills.Value == 1 then
task.wait(4.5)
if selfKills == 2 then
task.wait(4.5)
if selfKills == 3 then
print("Success!")
end
end
end
end
while task.wait() do
if selfKills.Value >= 1 then
task.wait(4.5)
if selfKills.Value >= 2 then
task.wait(4.5)
if selfKills.Value >= 3 then
print("Success!")
end
end
selfKills.Value = 0
end
end
local damagedBy = script.Parent
local h = script.Parent.Parent:WaitForChild("Humanoid")
local hrp = h.Parent:WaitForChild("HumanoidRootPart")
while task.wait() do
if selfKills.Value >= 1 then
task.wait(4.5)
if selfKills >= 2 then
task.wait(4.5)
if selfKills >= 3 then
print("Success!")
end
end
selfKills = 0
end
end