(SOLVED)Impact Frames issue

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!

3 Likes

Please copy/paste the entire error line here. ‘Unable to cast value to object’ doesn’t let anyone know what line of code or what item Value needs to be looked at.

1 Like

@Scottifly 15:19:12.796 Unable to cast value to Object - Server - Script:26 this is the error

1 Like

On line 26 you are attempting to use FireClient on a number.

game.ReplicatedStorage.Events.ImpactFrameEvent:FireClient(1, Color3.new(0, 0, 0), blades, plr.Character, hit.Parent, Color3.new(0,0,0))

The FireClient method needs a player object as the first argument passed, and then the rest of your params

Should look something like this

game.ReplicatedStorage.Events.ImpactFrameEvent:FireClient(plr, 1, Color3.new(0, 0, 0), blades, plr.Character, hit.Parent, Color3.new(0,0,0))

Also for better code practice you should initialize a variable for each thing you use multiple times. I noticed you used :WaitForChild(“HumanoidRootPart”) alot when you can make that a variable. Same thing with the Values.

local values = plr:WaitForChild("Values")
local moveActive = values:WaitForChild("MoveActive")

-- Also instead of checking == false you can do if not value then -- etc...
if not moveActive.Value then
    moveActive.Value = true
    -- etc.
end
1 Like

Its this line right here:

game.ReplicatedStorage.Events.ImpactFrameEvent:FireClient(1, Color3.new(0, 0, 0), blades, plr.Character, hit.Parent, Color3.new(0,0,0))
1 Like

Check my reply I’ve edited it. If it solves your issue please mark it as resolved. :slight_smile:

1 Like

Sorry for the late reply, i was at school(and sleeping) but it hasnt worked, still gives me the Unable to cast value to Object error

1 Like

Are you sure you’re passing the player as the first variable for fire client? That’s the only line that would cause that error.

Check if plr.Character exists and blades is not nil, and hit.Parent is also not nil

1 Like

Yeah, i just fixed it, but i think i found the issue, i put the localscript for the impact frame handling in Lighting lol. the result is ok but ill mark yours as the solution because it fixed one of the problems lol

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.