Server Script and using LocalPlayer? Use a PlayerAdded event to get the player, because LocalPlayer is only for client scripts (i.e. Local Scripts)
Are you sure you are editing the correct script? That should be working fine. I looked at the origin of the error and there doesn’t seem to be anything wrong.
so what do i add, im confused right now
local HttpService = game:GetService("HttpService")
local playerCaught = {}
-- Replace the webhook URL below with your own Discord webhook URL
local webhookUrl = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
game.Players.PlayerAdded:Connect(function(player)
while true do
wait(0.5) -- dont delete this or script can crash
if player.Character.Humanoid.WalkSpeed > 16 then -- if you have any shift to sprint scripts change 16 to value of running speed
if player.Name == "Insert admin name here" or playerCaught[player.Name] then -- this protects owner and admins from getting kicked (to add more just add 'or player.Name == "Name here"' before then)
-- do nothing
else
playerCaught[player.Name] = true -- set the player as caught
-- send message to Discord webhook
local message = {
["content"] = player.Name .. " is speed hacking!"
}
local encodedMessage = HttpService:JSONEncode(message)
HttpService:PostAsync(webhookUrl, encodedMessage)
print(player.Name.." is speed hacking") --this kicks player. you can change the message
end
end
end
end)
If this is seriously a server script then I must agree with @hasoco here.
You will need to do this upon the player being added to the game.
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
-- do something with the character
end)
end)
Otherwise just convert your script to a localscript, it should work that way too.
is this good?
because in getting an error on
local Player = game.Players:GetPlayerFromCharacter()
here is the script
local Player = game.Players:GetPlayerFromCharacter()
local HttpService = game:GetService("HttpService")
local playerCaught = {}
local webhookUrl = "example here"
game.Players.PlayerAdded:Connect(function(player)
while true do
wait(0.5) -- dont delete this or script can crash
if player.Character.Humanoid.WalkSpeed > 16 then -- if you have any shift to sprint scripts change 16 to value of running speed
if player.Name == "Insert admin name here" or playerCaught[player.Name] then -- this protects owner and admins from getting kicked (to add more just add 'or player.Name == "Name here"' before then)
-- do nothing
else
playerCaught[player.Name] = true -- set the player as caught
-- send message to Discord webhook
local message = {
["content"] = player.Name .. " is speed hacking!"
}
local encodedMessage = HttpService:JSONEncode(message)
HttpService:PostAsync(webhookUrl, encodedMessage)
print(player.Name.." is speed hacking") --this kicks player. you can change the message
end
end
end
end)
Remove the Player variable on the first line, because the player variable will be defined in the PlayerAdded event.
so what do i do? i dont understand
Just remove the Player variable at the first line…
But when i remove it, there isnt anything thats being printed in the output. So it means that is doesnt work, and im not getting any errors.
Maybe because you didn’t change the speed of your humanoid, and it isnt detecting anything.
here is a short clip showing it of
Did you whitelist yourself from the Anti-Cheat? Are there any errors from the same script?
is it maybe the category its in currently?
Yes, it is. Server Scripts dont work in StarterGui, put it in ServerScriptService
Omg thank you so much it worked
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.