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:
local rs = game:GetService("ReplicatedStorage")
local remotes = rs:WaitForChild("Remotes")
local telekinesisCooldown = 3
local deBounces = {["abilityCooldown"] = false, ["toggleCooldown"] = false}
game:GetService("Players").PlayerAdded:Connect(function(plr)
local playerFolder = Instance.new("Folder", rs:WaitForChild("ActiveAbilities"))
playerFolder.Name = plr.Name
local deBounceFolder = Instance.new("Folder", rs:WaitForChild("deBounce"))
deBounceFolder.Name = plr.Name
for debounceName, value in pairs(deBounces) do
local deBounceBool = Instance.new("BoolValue", deBounceFolder)
deBounceBool.Name = debounceName
end
local telekinesisActive = Instance.new("BoolValue", playerFolder)
telekinesisActive.Name = script.Name
end)
local function setPos(mouseData, plr)
repeat
mouseData[1] = plr.PlayerGui.givemouseData:InvokeClient(plr)[1]
if mouseData[2] ~= nil then
mouseData[2].Position = mouseData[1]
end
until not rs.ActiveAbilities[mouseData[3].Name][script.Name].Value or plr.Character.Humanoid.Health <= 0
end
remotes.telekinesis.OnServerEvent:Connect(function(plr)
local deBounce = rs.deBounce[plr.Name].abilityCooldown
if plr.Character then
if plr.Character.telekinesis.Value and not deBounce.Value then
deBounce.Value = true
local playerMouseData = plr.PlayerGui.givemouseData:InvokeClient(plr) -- This is where it gets stuck
local partToMove = playerMouseData[2]
print(playerMouseData[2])
if playerMouseData[2] ~= "void" and playerMouseData[2] ~= nil then
game:GetService("Chat"):Chat(plr.Character.Head, "Etativel", "Red")
setPos(playerMouseData, plr)
end
wait(telekinesisCooldown)
deBounce.Value = false
end
end
end)
And here is the localscript sending the mousedata:
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local giveData = player.PlayerGui:WaitForChild("givemouseData")
giveData.OnClientInvoke = function()
local mouseData = {mouse.hit.Position, mouse.Target, game:GetService("Players").LocalPlayer}
return mouseData
end
