What should I do to the script to make it work and not get the output of an attempt to index nil with ‘Character.’ I believe this form of code used to work… I could rewrite the script to detect animation wise of when the player moves/jumps… however, I keep getting lost.
I haven’t script in awhile and feel a little lost!
local character = player.Character or Player.CharacterAdded:Wait()
This bit of code checks if the player has a character, and if it doesn’t it waits until it does.
Add a WaitForChild by the humanoid as well: local humanoid = character:WaitForChild("Humanoid").
This means that if the Humanoid hasn’t spawned in by the time the script has run, it will wait for it to spawn in.
Remove your while true do loop, you don’t need it because GetPropertyChangedSignal will fire whenever the humanoid is updated, you don’t need to have it in a loop.
Hope that this could help!
(p.s if this is in a server script it won’t work because LocalPlayer can only be accessed via a local script, which is what I think @Katrist was getting at)
--//Functions
game:GetService("Players").PlayerAdded:Connect(function(player) -- Fires when the player joins
player.CharacterAdded:Connect(function(character) -- Fires when the player's character loads
character.Humanoid:GetPropertyChangedSignal("Jump"):Connect(function() -- Fires when the player's character's jump value changes
if character.Humanoid.Jump == true then -- Checks if the jump value is true (so it doesn't kick the player again if the server lags and the player's value changes back to false)
player:Kick("You Jumped!") -- Kicks the player
end
end)
end)
end)
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key, processed)
if processed then
return
end
if key.KeyCode == Enum.KeyCode.Space then
print("Jumped!")
end
end)
As primitive as it gets, local script inside StarterPlayerScripts folder (assuming you wanted this to work in a local script).
--//Services
local Players = game:GetService("Players")
--//Functions
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Humanoid:GetPropertyChangedSignal("Jump"):Connect(function() -- Kicks the player for jumping
if character.Humanoid.Jump == true then
player:Kick("You Jumped!")
end
end)
character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function() -- Kicks the player for walking
if character.Humanoid.MoveDirection.Magnitude > 0 then
player:Kick("You Walked!")
end
end)
end)
end)
Keep in mind that most changes in the Humanoid do not replicate to the server. And if you’re doing this in the client it can easily be bypassed by exploiters.