Hello!
Yesterday I updated one of my moves that now has impact frames, It worked perfectly, until today where i was greeted with this error when i tested it again: Unable to cast value to Object. I tried everything but nothing worked, Here is the code:
local TS = game:GetService("TweenService")
local fireing = false
local impactFramePlayed = false
script.Parent.OnServerEvent:Connect(function(plr,pos)
local pushForce = 150
local mouse = plr:GetMouse()
local hrp = plr.Character:WaitForChild("HumanoidRootPart")
if fireing == false then
if plr:WaitForChild("Values").MoveActive.Value == false then
plr:WaitForChild("Values").MoveActive.Value = true
fireing = true
local position = pos
local hrp = plr.Character:WaitForChild("HumanoidRootPart")
hrp.Anchored = true
local blades = game.ReplicatedStorage.Blade:Clone()
blades.Parent = workspace
blades.CFrame = CFrame.new(Vector3.new(pos.X,-15,pos.Z))
local TS = game:GetService("TweenService")
TS:Create(blades, TweenInfo.new(0.35,Enum.EasingStyle.Quad, Enum.EasingDirection.In, 1, false, 0), {Position = Vector3.new(position.X, 4.5, position.Z)}):Play()
blades.Touched:Connect(function(hit)
if game.Players:FindFirstChild(hit.Parent.Name) or hit.Parent.Name == "TestDummy" then
if impactFramePlayed == false then
impactFramePlayed = true
hit.Parent:WaitForChild("HumanoidRootPart").Position = hit.Parent:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,8.5,0)
hit.Parent:WaitForChild("HumanoidRootPart").Anchored = false
game.ReplicatedStorage.Events.ImpactFrameEvent:FireClient(1, Color3.new(0, 0, 0), blades, plr.Character, hit.Parent, Color3.new(0,0,0))
wait(1)
hit.Parent:WaitForChild("HumanoidRootPart").Anchored = false
local vel = Instance.new("BodyVelocity", plr.Parent.HumanoidRootPart)
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = plr.Parent.HumanoidRootPart
vel.Velocity = Vector3.new(1,1,1) * Vector3.new(0,10,0) * pushForce
vel.Name = "SmallMoveVel"
hit.Parent:WaitForChild("Humanoid"):TakeDamage(65)
end
end
end)
wait(1)
blades["A"]:Destroy()
wait(1.5)
TS:Create(blades, TweenInfo.new(0.35,Enum.EasingStyle.Quad, Enum.EasingDirection.In, 1, false, 0), {Transparency = 1}):Play()
wait(2)
blades:Destroy()
fireing = false
impactFramePlayed = false
hrp.Anchored = false
plr:WaitForChild("Values").MoveActive.Value = false
else
return
end
end
end)
ImpactFramesEvent code:
game.ReplicatedStorage.Events.ImpactFrameEvent.OnClientEvent:Connect(function(Time,Color,Thing,Player1,Player2,Color2)
local LightingStuff = game.Lighting.ImpactFrame
local bladeHighLight = game.ReplicatedStorage.EffectsForMoves.ImpactFrame:Clone()
local highLight = game.ReplicatedStorage.EffectsForMoves.ImpactFrame:Clone()
local highLight2 = game.ReplicatedStorage.EffectsForMoves.ImpactFrame:Clone()
--create a way to make impact frames which will enabled LightningStuff, and clone bladeHighlight, Highlight and Highlight2 to Player1, and player2, and thing. Make the lighting changes only visible to those player1, and player2 thank you. Make it visible to only player1 and player2(Or if its name is TestDummy then it will only show for player1)
LightingStuff.Enabled = true
bladeHighLight.Parent = Thing
highLight.Parent = Player2
highLight2.Parent = Player1.Character
if Player1.Name == "TestDummy" then
Player1.CameraMode = Enum.CameraMode.LockFirstPerson
end
if Player2.Name == "TestDummy" then
Player2.CameraMode = Enum.CameraMode.LockFirstPerson
end
wait(Time)
--make the impact frames disappear after 0.5 seconds.
bladeHighLight:Destroy()
LightingStuff.Enabled = false
highLight:Destroy()
highLight2:Destroy()
end)
Thank you!