This script keeps crashing the client

Hello,

I have taken the cuff script from @Marxy to try and recreate the drag script from @Frazzle so that it doesn’t require essential mode. When you type in the command and the clients id it crashes that clients game. Any help is appreciated.

Client.lua

drag = false

RegisterNetEvent("dr:drag")
AddEventHandler('dr:drag', function(pl)
	otherid = tonumber(pl)
	drag = not drag
end)

Citizen.CreateThread(function()
	while true do
		if drag then
			local ped = GetPlayerPed(GetPlayerFromServerId(otherid))
			local myped = GetPlayerPed(-1)
			AttachEntityToEntity(myped, ped, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
		else
			DetachEntity(GetPlayerPed(-1), true, false)		
		end
		Citizen.Wait(0)
	end
end)

Server.lua

AddEventHandler('chatMessage', function(source, n, message)
    cm = stringsplit(message, " ")

    if cm[1] == "/drag" then
      CancelEvent()
    if tablelength(cm) > 1 then
      local tPID = tonumber(cm[2])
      TriggerClientEvent("dr:drag", tPID)
    end
  end
end)

function stringsplit(self, delimiter)
  local a = self:Split(delimiter)
  local t = {}

  for i = 0, #a - 1 do
     table.insert(t, a[i])
  end

  return t
end

function tablelength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end

For FX server? Or CFX?

CFX at the moment. I know, I should be doing FX

Well than you can just use the regular drag script

I’m trying to create one that doesn’t require essential mode

you said it crashing the game , have you check the log for getting the last error ? type the error you got plz

Updated to FX Server and try getting it to work, there’s no point trying to port/write scripts to CFX anymore.

3 Likes