Have a script that includes data, if the player has none it is set to false, but it gives me the error “Unable to cast value to object” on line 22
script (Server)
local Players = game:GetService("Players")
local RP = game:FindService("ReplicatedStorage")
local Event = RP.CheckingIfInAir
local RemoteFunction = RP.RemoteFunction
Event.OnServerEvent:Connect(function(player)
print("3")
local DataManager = require(game:GetService("ReplicatedStorage").DataManager)
local data = DataManager:Get(player)
if data then
local TPoseEquipped = data.TPoseEquipped
local TPoseOwned = data.TPoseOwned
local GoldenHookEquipped = data.GoldenHookEquipped
local GoldenHookOwned = data.GoldenHookOwned
RemoteFunction:InvokeClient(data, TPoseEquipped, TPoseOwned, GoldenHookEquipped, GoldenHookOwned)
else
RemoteFunction:InvokeClient(false, false, false, false, false) --Line 22
end
end)
and if it helps this is the client the function is being sent to.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Humanoid.Parent:WaitForChild("HumanoidRootPart")
local RP = game:FindService("ReplicatedStorage")
local Event = RP.CheckingIfInAir
local RemoteFunction = RP.RemoteFunction
-----------Animations---------------------
--//Ani 1 (Defualt)//--
local Animation = script.DefualtSwing
local AnimationTrack = Humanoid:LoadAnimation(Animation)
--//Ani 2 (T-Pose)//--
local Animation2 = script.TPoseSwing
local Animation2Track = Humanoid:LoadAnimation(Animation2)
--// Ani 3 (UpsideDown)//--
local Animation3 = script.UpsideDown
local Animation3Track = Humanoid:LoadAnimation(Animation3)
-------------------------------------------
local RopeAmount = Player:WaitForChild("NumberOfHooks"):WaitForChild("Amount")
local EventDB = false
while true do
if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
print("1")
Event:FireServer()
wait(.5)
end
wait(.5)
end
RemoteFunction.OnClientInvoke = function(player,data,TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)
print("2")
if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
if RopeAmount.Value == 1 then
local char = Player.Character
if data then
if TPoseEquipped.Value == true then
Animation2Track:Play()
Animation2Track.Looped = true
elseif TPoseEquipped.Value == false then
AnimationTrack:Play()
AnimationTrack.Looped = true
end
else
AnimationTrack:Play()
AnimationTrack.Looped = true
end
elseif RopeAmount.Value == 0 then
if data then
if TPoseEquipped.Value == true then
Animation2Track:Stop()
elseif TPoseEquipped.Value == false then
AnimationTrack:Stop()
end
else
AnimationTrack:Stop()
end
end
end
end