Some users are reporting that sometimes when you reset and you are stealing it adds the stolen item to your inventory, and it dodges the conn3.
stealEvent.OnServerInvoke = function(player, object)
local originalPlayer = Players[object.Parent.Parent.Name]
if not object then
warn("Trying to steal non-existent object")
return false
end
if not originalPlayer then
warn("Object doesn't belong to any player")
return false
end
if player:GetAttribute("Stealing") == true then
warn("Trying to steal whilst already stealing another object")
return false
end
local char = player.Character
if not char or not char.PrimaryPart then
warn("No player character or PrimaryPart, possible exploiter")
return false
end
local ownedPlotSpots = {}
for _, ownedObject in ipairs(PlayerData[player].OwnedObjects) do
ownedPlotSpots[ownedObject.PlotSpot] = true
end
local openPlotSpot = getPlotSpot(player)
if openPlotSpot == nil then
warn("Player has no more plot spaces left")
return false
end
if (char.PrimaryPart.Position - object.PrimaryPart.Position).Magnitude > 10 then
warn("Player is too far from object, possible exploiter")
return false
end
if object:GetAttribute("BeingStolen") then
return false
end
object:SetAttribute("BeingStolen", true)
local clone = object:Clone()
clone.PrimaryPart.Anchored = false
local frontOffset = char.PrimaryPart.CFrame.LookVector
clone:SetPrimaryPartCFrame(char.PrimaryPart.CFrame + frontOffset)
clone.Parent = workspace
local weld = Instance.new("WeldConstraint")
weld.Part0 = clone.PrimaryPart
weld.Part1 = char.PrimaryPart
weld.Parent = clone.PrimaryPart
player.Character.Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed / 2
for _, part in pairs(clone:GetChildren()) do
if part:IsA("BasePart") then
part.CanCollide = false
part.Massless = true
end
if part:IsA("Script") or part:IsA("Model") or part.Name == "CollectPad" then
part:Destroy()
end
end
if clone.PrimaryPart:FindFirstChild("Action") then
clone.PrimaryPart.Action:Destroy()
end
player:SetAttribute("Stealing", true)
local conn
conn = player:GetAttributeChangedSignal("Stealing"):Connect(function()
if player:GetAttribute("Stealing") == false then
player.Character.Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
object:SetAttribute("BeingStolen", false)
clone:Destroy()
conn:Disconnect()
end
end)
local conn3
local conn2
stealNotifEvent:FireClient(originalPlayer, player.Name, object.Name)
conn3 = char.Humanoid.Died:Connect(function()
player:SetAttribute("Stealing", false)
object:SetAttribute("BeingStolen", false)
conn:Disconnect()
clone:Destroy()
if conn2 then
conn2:Disconnect()
end
conn3:Disconnect()
end)
conn2 = workspace.Plots:FindFirstChild(player.Name).Pivot.Touched:Connect(function(hit)
if hit.Parent.Name == player.Name then
clone:Destroy()
local plotSpot = object:GetAttribute("Spot")
if not plotSpot then
warn("Object isn't on a plot spot")
player:SetAttribute("Stealing", false)
conn2:Disconnect()
return false
end
if not originalPlayer then
warn("Original player left")
player:SetAttribute("Stealing", false)
conn2:Disconnect()
return false
end
for i = #PlayerData[originalPlayer].OwnedObjects, 1, -1 do
if PlayerData[originalPlayer].OwnedObjects[i].PlotSpot == plotSpot then
table.remove(PlayerData[originalPlayer].OwnedObjects, i)
break
end
end
table.insert(PlayerData[player].OwnedObjects, {Object = object.Name, Mutations = {}, PlotSpot = openPlotSpot})
table.insert(PlayerData[player].ObjectsEverOwned, {Object = object.Name})
local plot = workspace.Plots:FindFirstChild(player.Name)
local base = plot.ObjectSpawns["Spot" .. plotSpot].CFrame
local newOwnedObject = ReplicatedStorage.Objects:FindFirstChild(object.Name):Clone()
newOwnedObject.Parent = plot.Objects
newOwnedObject:PivotTo(base * CFrame.new(0, 3, 0))
newOwnedObject.PrimaryPart.Anchored = true
newOwnedObject:SetAttribute("Spot", openPlotSpot)
attachCollector(newOwnedObject, player, Objects.Data[object.Name], base)
player:SetAttribute("Stealing", false)
object:Destroy()
PlayerState.Increment(player, "Steals", 1)
PlayerState.SaveData(player)
updateIndexEvent:FireClient(player)
conn2:Disconnect()
end
end)
return true
end
If you know the issue, please let me know.