Im trying to make a code that detects whenever another player jumps. The problem is that when the other player resets it messes up the code.
Atempt:
function BlockWatcher(char)
local hum = char.Humanoid
hum:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if hum.FloorMaterial == Enum.Material.Air then -- Jumped
print("JUMPED")
elseif hum.FloorMaterial ~= Enum.Material.Air then -- Landed
print("Landed")
end
end)
end
for i,v in ipairs(game.Players:GetPlayers()) do
BlockWatcher(v.Character)
v.CharacterAdded:Connect(function(Char)
BlockWatcher(Char)
end)
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
BlockWatcher(char)
end)
end)
but when the character resets, it doesn’t apply to them any more. How do I fix that?
for i,v in ipairs(game.Players:GetPlayers()) do
BlockWatcher(v.Character or v.CharacterAdded:wait())
v.CharacterAdded:Connect(function(Char)
BlockWatcher(Char)
end)
end
local Players = game:GetService("Players")
local function CharAdded(Char)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if Humanoid.Jump == true then
print(Char.Name, "Jumped")
else
print(Char.Name, "Landed")
end
end)
end
game.Players.PlayerAdded:Connect(function(Plr)
Plr.CharacterAdded:Connect(CharAdded)
end)
The only issue that I could see is where the script actually is, cause there are some locations where some scripts can’t fully run
Strange, I’ve never really had any issues with a delay from that (Thanks ROBLOX)
Not sure if using GetPropertyChangedSignal("Jump") would result in the same outcome, it’s strange how some Events aren’t just designed to work properly as expected
Why couldn’t you just do this as a regular script inside ServerScriptService? It would work exactly the same & it’ll be server-sided as well, so you could check for when a Character starts to jump
State changes replicate. Just use a Server Script to accomplish this. If you intend to hook this to each player that joins, make good use of StarterCharacterScripts with a server script and you can pull what you want to achieve there.
If you’re trying to implement specific checks that usually only 1 script would do, have a configuration somewhere in the game, for example dying on jump and set the script for that one player to listen to it.
For example, if the BoolValue was true, kill them if a State change to “Jumping” is true.