I tried making the Kill Part’s CanCollide property to true and it worked, but i wonder if there is a way to fix this issue without doing that.
Here is the code i used:
local killPart = script.Parent -- Kill part position
killPart.Touched:Connect(function(hit)
local char = hit.Parent -- Character
local hum = char:FindFirstChild("Humanoid") -- Humanoid
if hum then -- If humanoid then...
if hum.Health ~= 0 then -- Makes sure that character is not dead
hum.Health = 0 -- Kills the character
end
end
end)
Could You Try to Print Something When the Player Touches the Part ? Just After .Touched:Connect(function(hit)
Once You did that Try To Keep Jumping and go over the Part and Check if it Prints anything or not.
This will make us know that when the player keeps on jumping, Does the Touch event actually fire or not
I have a small suggestion that could work if the event actually fires, make it do a loop, so that way if the input stops, the script will still do the function through the loop.
Hello @YT_Forceman , I tried updating the code to this:
local killPart = script.Parent -- Kill part position
killPart.Touched:Connect(function(hit)
print("Part has beed touched")
local char = hit.Parent -- Character
local hum = char:FindFirstChild("Humanoid") -- Humanoid
if hum then -- If humanoid then...
if hum.Health ~= 0 then -- Makes sure that character is not dead
hum.Health = 0 -- Kills the character
end
end
end)
But when i keep jumping on the part nothing prints on the output
No, LocalScripts only work on client, server scripts work on server, he cannot use a local script literally let me think about this for a bit, and I will try to come up with an answer
Killparts in every major obby are local,
in fact, they are local as in they used a Touched connection on either the humanoid or a custom hitbox for the player.
After all, servers dont get the real time position as replication works in 20hz.
Hello @Feedekaiser , I tried replacing the Server Script by a Local Script, but actually nothing happens, maybe because the local scripts don’t work in Workspace.
local killPart = script.Parent;
killPart.Touched:Connect(function(Part)
if Part.Parent:FindFirstChild("Humanoid") ~= nil then
Part.Parent.Humanoid.Health = 0;
end
end)
@Feedekaiser , I tried your solution and it actually worked!
Here is the script inside the StarterPlayerScripts:
local killPart = game.Workspace.KillPart
killPart.Touched:Connect(function(hit)
print("Part has beed touched")
local char = hit.Parent -- Character
local hum = char:FindFirstChild("Humanoid") -- Humanoid
if hum then -- If humanoid then...
if hum.Health ~= 0 then -- Makes sure that character is not dead
hum.Health = 0 -- Kills the character
end
end
end)
local killPart = script.Parent
local function onPartTouch(hit)
local hum = hit.Parent.Humanoid
if hum then
hum.Health = 0
end
print("Part has been touched!")
end
killPart.Touched:Connect(onPartTouch)
Should not be neccessary. Nor should this system be a local script as well. Having this in serverscript service as a server script should be fine. Though server scripts can run in workspace as well so that is not the problem. I would recomend using functions such as break joints to make sure you actually kill the player. If the script is a server script and is located either in server script service or the workspace this script should work fine though
Fair enough but yours wont work either, he will have to make a nee script every time a nee one is created, due to the fact that if the parts are the same name roblox will not be able to find the actual one yout referenceing
No
if you have multiple killparts, consider using something like this
game.Players.LocalPlayer.CharacterAdded:Connect(funcition(character)
character:WaitForChild'Humanoid'.Touched:Connect(function(x)
if x.Name == 'KillPart' then
character:BreakJoints()
end
end)
end)