A friend and I are trying to work on a script that detects if a player is teleporting things from the workspace to them. However, this is easier said than done and the script doesn’t seem to work. Any help would be appreciated, thanks!
local TS = game:GetService("TweenService")
local info = TweenInfo.new(0.15, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
local antiHack = require(script.Parent.Parent.Modules.Check)
task.spawn(function()
workspace.ChildAdded:Connect(function(item)
local lastPos = item.PrimaryPart.Position
if item:FindFirstChild("FruitValue") then
antiHack.Set(item.PrimaryPart, game.StarterPlayer.CharacterWalkSpeed + 2)
local _playersWhoPickedUp = {}
local plrs = game:GetService("Players")
local container = item.Container
local RP = game:GetService("ReplicatedStorage")
local Remotes = RP.Remotes
local RemoveLocal = Remotes.RemoveIngredientLocal
local UpdateClient = Remotes.UpdateClient
local debounce = false
item.Container.Touched:Connect(function(hit)
local plr = plrs:GetPlayerFromCharacter(hit.Parent)
local position = antiHack.GetPosition(item.PrimaryPart, plr.Name)
if (position - item.PrimaryPart.Position).Magnitude > 10 then return end
task.wait(.5)
item.Container:Destroy()
if not debounce and plr and hit.Name ~= "Main" then
print("Fired")
debounce = true
plr.stats.Ingredients.Value += (item.Amount.Value * plr.stats.IngredientMultiplier.Value)
item:Destroy()
elseif hit.Name == "Main" then
plr = plrs:GetPlayerFromCharacter(hit.Parent.Parent)
if _playersWhoPickedUp[plr] then return end
_playersWhoPickedUp[plr] = true
plr.stats.Ingredients.Value += (item.Amount.Value * plr.stats.IngredientMultiplier.Value)
UpdateClient:FireClient(plr, item)
end
task.wait(1)
debounce = false
end)
end
end)
end)
local module = {}
module.Set = function(part, maxSpeed)
part:SetAttribute("Position", part.Position)
part:SetAttribute("MaxSpeed", maxSpeed)
part:SetAttribute("Time", time())
end
local counter = 0
module.GetPosition = function(part, name)
for i, v in pairs(workspace:FindFirstChild(name):GetChildren()) do
if v:IsA("Tool") then return end
end
for i, v in pairs(game.Players:GetChildren()) do
if v:FindFirstChild(name) then
for i, m in pairs(v.Backpack:GetChildren()) do
if v:IsA("Tool") then return end
end
end
end
counter += 1
local position = part:GetAttribute("Position")
local maxSpeed = part:GetAttribute("MaxSpeed")
local deltaTime = math.max(time() - part:GetAttribute("Time"), 0.001)
local magnitude = (part.Position - position).Magnitude
local speed = magnitude / deltaTime
if counter < 3 then
speed = 16
end
print(speed)
if speed > maxSpeed then plr:Kick("Nice Try Bucko") end
part:SetAttribute("Position", part.Position)
part:SetAttribute("MaxSpeed", maxSpeed)
part:SetAttribute("Time", time())
return part.Position
end
return module