Script gets stuck when firing a client remotefunction when player dies, why is this?
So i am currently making a script which involves the server getting some information about the players mouse, it all works as intended until the player dies. When the player dies the script that fires the remotefunction that gives the mousedata, never gets the mousedata and just gets stuck. Does anybody know why this happens?
Here is the function in the main that needs the mousedata script:
01 | local rs = game:GetService( "ReplicatedStorage" ) |
02 | local remotes = rs:WaitForChild( "Remotes" ) |
03 | local telekinesisCooldown = 3 |
04 | local deBounces = { [ "abilityCooldown" ] = false , [ "toggleCooldown" ] = false } |
06 | game:GetService( "Players" ).PlayerAdded:Connect( function (plr) |
07 | local playerFolder = Instance.new( "Folder" , rs:WaitForChild( "ActiveAbilities" )) |
08 | playerFolder.Name = plr.Name |
10 | local deBounceFolder = Instance.new( "Folder" , rs:WaitForChild( "deBounce" )) |
11 | deBounceFolder.Name = plr.Name |
13 | for debounceName, value in pairs (deBounces) do |
14 | local deBounceBool = Instance.new( "BoolValue" , deBounceFolder) |
15 | deBounceBool.Name = debounceName |
18 | local telekinesisActive = Instance.new( "BoolValue" , playerFolder) |
19 | telekinesisActive.Name = script.Name |
22 | local function setPos(mouseData, plr) |
25 | mouseData [ 1 ] = plr.PlayerGui.givemouseData:InvokeClient(plr) [ 1 ] |
27 | if mouseData [ 2 ] ~ = nil then |
28 | mouseData [ 2 ] .Position = mouseData [ 1 ] |
31 | until not rs.ActiveAbilities [ mouseData [ 3 ] .Name ] [ script.Name ] .Value or plr.Character.Humanoid.Health < = 0 |
35 | remotes.telekinesis.OnServerEvent:Connect( function (plr) |
36 | local deBounce = rs.deBounce [ plr.Name ] .abilityCooldown |
38 | if plr.Character.telekinesis.Value and not deBounce.Value then |
41 | local playerMouseData = plr.PlayerGui.givemouseData:InvokeClient(plr) |
42 | local partToMove = playerMouseData [ 2 ] |
44 | print (playerMouseData [ 2 ] ) |
45 | if playerMouseData [ 2 ] ~ = "void" and playerMouseData [ 2 ] ~ = nil then |
46 | game:GetService( "Chat" ):Chat(plr.Character.Head, "Etativel" , "Red" ) |
47 | setPos(playerMouseData, plr) |
50 | wait(telekinesisCooldown) |
51 | deBounce.Value = false |
And here is the localscript sending the mousedata:
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local mouse = player:GetMouse() |
3 | local giveData = player.PlayerGui:WaitForChild( "givemouseData" ) |
5 | giveData.OnClientInvoke = function () |
6 | local mouseData = { mouse.hit.Position, mouse.Target, game:GetService( "Players" ).LocalPlayer } |