What do you want to achieve? Keep it simple and clear!
i want the script to sense when a player(a different player not yours) touches the hitbox part
What is the issue? Include screenshots / videos if possible!
the touch sensing part of the script isnt working the rest is
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried removing the “if not results[i]:IsDescendantOf(player.Character) then” part but it still didnt work
also the part isnt anchored so that isnt why
script.Parent.OnServerEvent:Connect(function(player)
local rps = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local players = game:GetService("Players")
local Hitbox = rps.KISenseHitBox:Clone()
Hitbox.Parent = player.Character
Hitbox.CFrame = player.Character.HumanoidRootPart.CFrame
local weld = Instance.new("Weld")
weld.Part0 = player.Character.HumanoidRootPart
weld.Part1 = Hitbox
weld.Parent = player.Character.HumanoidRootPart
local results = Hitbox:GetTouchingParts()
for i, obj in pairs(results) do
if not results[i]:IsDescendantOf(player.Character) then
local ehumanoid = results[i].Parent:FindFirstChild("Humanoid")
local ehumrp = results[i].Parent:FindFirstChild("HumanoidRootPart")
if ehumanoid and ehumanoid.Health > 0 then
print("hi")
end
end
end
end)
1. Ensure that the event is in fact being fired
You can do this by using prints at the beginning of the provided script, like this:
script.Parent.OnServerEvent:Connect(function(player)
print(“hi”)
local rps = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local players = game:GetService("Players")
local Hitbox = rps.KISenseHitBox:Clone()
Hitbox.Parent = player.Character
Hitbox.CFrame = player.Character.HumanoidRootPart.CFrame
local weld = Instance.new("Weld")
weld.Part0 = player.Character.HumanoidRootPart
weld.Part1 = Hitbox
weld.Parent = player.Character.HumanoidRootPart
local results = Hitbox:GetTouchingParts()
for i, obj in pairs(results) do
if not results[i]:IsDescendantOf(player.Character) then
local ehumanoid = results[i].Parent:FindFirstChild("Humanoid")
local ehumrp = results[i].Parent:FindFirstChild("HumanoidRootPart")
if ehumanoid and ehumanoid.Health > 0 then
print("hi")
end
end
end
end)
2. Change the use of i to obj
If I remember correctly, using i will use a numerical value of the object’s position in the table you’re using. Using obj will find the object in the Explorer and use that instead.
Example:
script.Parent.OnServerEvent:Connect(function(player)
local rps = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local players = game:GetService("Players")
local Hitbox = rps.KISenseHitBox:Clone()
Hitbox.Parent = player.Character
Hitbox.CFrame = player.Character.HumanoidRootPart.CFrame
local weld = Instance.new("Weld")
weld.Part0 = player.Character.HumanoidRootPart
weld.Part1 = Hitbox
weld.Parent = player.Character.HumanoidRootPart
local results = Hitbox:GetTouchingParts()
for i, obj in pairs(results) do
if not results[obj]:IsDescendantOf(player.Character) then
local ehumanoid = results[obj].Parent:FindFirstChild("Humanoid")
local ehumrp = results[obj].Parent:FindFirstChild("HumanoidRootPart")
if ehumanoid and ehumanoid.Health > 0 then
print("hi")
end
end
end
end)