Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Clear is not a valid member of Fire "Workspace.OsipStar4ik.Knife.Handle.Effect"?

Clear is not a valid member of Fire "Workspace.OsipStar4ik.Knife.Handle.Effect" help pls Knife Script:

-- rescripted by clockworkmine

-- Basic settings
local ALLOWED_DISTANCE = 8
local XP_PER_KILL = script.Parent.KillXP.Value

local tool = script.Parent
local debounce = false
local throwCooldown = false
local allowedToHit = false
local throwType = 0
local lastMouseHitPos = nil

local toolPlr
local animDraw = nil
local animStab = { nil, nil, nil }
local animThrow = nil

function enableEffects()
	
	-- Enable em
	for _, i in pairs(tool.Handle:GetChildren()) do
		if i.Name == "Effect" then
			i.Enabled = true
		end
	end
	
end

function disableEffects()
	
	-- Disable em
	for _, i in pairs(tool.Handle:GetChildren()) do
		if i.Name == "Effect" then
			i.Enabled = false
			i:Clear()
		end
	end
	
end

script.HitPlayer.OnServerEvent:connect(function(plr, hit)
	
	-- Make sure the hit is valid
	if hit == nil or hit.Parent == nil then
		return
	end
	
	-- Check if player (and not this player)
	if hit.Parent:FindFirstChild("Humanoid") and allowedToHit and plr == toolPlr then
		local chr = hit.Parent
		if chr ~= tool.Parent and chr.Humanoid.Health > 0 then
			
			-- Check if not on same team
			local okay = true
			local otherPlr = game.Players:GetPlayerFromCharacter(chr)
			if chr:FindFirstChild("Knife") then
				if chr.Knife.TeamColor.Value == tool.TeamColor.Value then
					okay = false
				end
			end
			if chr:FindFirstChild("Revolver") then
				if chr.Revolver.TeamColor.Value == tool.TeamColor.Value then
					okay = false
				end
			end
			if otherPlr.Backpack:FindFirstChild("Knife") then
				if otherPlr.Backpack.Knife.TeamColor.Value == tool.TeamColor.Value then
					okay = false
				end
			end
			if otherPlr.Backpack:FindFirstChild("Revolver") then
				if otherPlr.Backpack.Revolver.TeamColor.Value == tool.TeamColor.Value then
					okay = false
				end
			end
			
			-- Tell server to hit
			if okay and math.abs((hit.Position - tool.Handle.Position).Magnitude) <= ALLOWED_DISTANCE then
				
				-- Kill the player
				local chr = hit.Parent
				chr.Humanoid.Health = 0
				game.ServerScriptService.Functions.GameDeath:Fire(chr, (chr.Torso.Position - tool.Parent.Torso.Position).Unit, tool.Effect.Value)
				
				-- Award XP
				if XP_PER_KILL > 0 then
					local plr = game.Players:GetPlayerFromCharacter(tool.Parent)
					game.ServerScriptService.Functions.GiveXP:Fire(plr, XP_PER_KILL, 0)
				end
				plr.Achievements.StabKills.Value = plr.Achievements.StabKills.Value + 1
				
				-- Play hit sound and effect
				game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Hit)
				game.ReplicatedStorage.Interactions.Client.RunKillFlash:FireClient(toolPlr)
				
			end
			
		end
	end
	
end)

script.ClientStab.OnServerEvent:connect(function(plr)
	
	-- Make sure correct player
	if plr ~= toolPlr then
		return
	end
	
	-- See if should
	if not debounce then
		debounce = true

		-- Allow hitting other players		
		allowedToHit = true
		
		-- Play the stab animation
		animStab[math.random(1, #animStab)]:Play()
		wait(0.2)
		game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Swing)
		
	end
	
end)

function throwKnife()
	
	wait(animDraw.Length)
	
	local copy = tool.Handle:clone()
	copy.Name = "KnifeProjectile"
	copy.Transparency = 0
	copy.Anchored = true
	local scr = script.KnifeProjectileScript:clone()
	scr.Owner.Value = tool.Parent
	scr.TeamColor.Value = tool.TeamColor.Value
	local hitPos = nil
	if throwType == 0 then
		hitPos = script.ServerGetMouseHitPosition:InvokeClient(toolPlr)
	elseif throwType == 1 then
		hitPos = lastMouseHitPos
	end
	scr.Velocity.Value = (hitPos - copy.Position).Unit * script.KnifeThrowSpeed.Value
	scr.Effect.Value = tool.Effect.Value
	scr.RotateAxis.Value = tool.RotateAxis.Value
	scr.GripCFrame.Value = (tool.NormalGrip.Value - tool.NormalGrip.Value.p):inverse()
	scr.Parent = copy
	
	-- Place in workspace
	copy.Parent = workspace
	scr.Disabled = false
	
	-- Make normal knife invisible
	tool.Handle.Transparency = 1
	disableEffects()
	
	-- Activate cooldown
	throwCooldown = true
	animDraw:Stop()
	
	spawn(function()
		wait(0.5)
		tool.Handle.Transparency = 0
		debounce = false
		wait(script.KnifeThrowCooldown.Value - 0.5)
		throwCooldown = false
	end)

end

script.ClientThrow.OnServerEvent:connect(function(plr)
	
	-- Make sure correct player
	if plr ~= toolPlr then
		return
	end
	
	-- See if should
	if not debounce and not throwCooldown then
		debounce = true
		
		animDraw:Play()
		throwKnife()
		-- Play the throw animation
		throwType = 0
		
	end
	
end)

script.ClientThrowStart.OnServerEvent:connect(function(plr)
	
	-- Make sure correct player
	if plr ~= toolPlr then
		return
	end
	
	-- See if should
	if not debounce and not throwCooldown and not animDraw.IsPlaying then
		debounce = true
		
		animDraw:Play()
		-- Play the throw animation
		throwType = 0
		throwKnife()
		
	end
	
end)

--[[script.ClientThrowEnd.OnServerEvent:connect(function(plr, hitPos)
	
	-- Make sure correct player
	if plr ~= toolPlr then
		return
	end
	
	-- See if should
	if animThrow.IsPlaying and animThrow.Speed == 0 then
		
		-- Finish the throw animation
		lastMouseHitPos = hitPos
		animThrow:AdjustSpeed(1)
		
	end
	
end)]]

tool.Equipped:connect(function()
	
	-- Set player
	toolPlr = game.Players:GetPlayerFromCharacter(tool.Parent)
	
	-- Load anim draw
	animDraw = tool.Parent.Humanoid:LoadAnimation(script.KnifeDraw)
	--[[animDraw.Stopped:connect(function()
		tool.Handle.Transparency = 0
		debounce = false
	end)]]
	
	-- Load anim stabs
	animStab[1] = tool.Parent.Humanoid:LoadAnimation(script.KnifeStab1)
	animStab[1].Stopped:connect(function()
		allowedToHit = false
		debounce = false
		tool.Handle.Transparency = 0
	end)
	animStab[2] = tool.Parent.Humanoid:LoadAnimation(script.KnifeStab2)
	animStab[2].KeyframeReached:connect(function(name)
		if name == "Beginning" then
			tool.Grip = tool.NormalGrip.Value * CFrame.Angles(0, 0, math.pi)
		end
	end)
	animStab[2].Stopped:connect(function()
		tool.Grip = tool.NormalGrip.Value
		allowedToHit = false
		debounce = false
		tool.Handle.Transparency = 0
	end)
	animStab[3] = tool.Parent.Humanoid:LoadAnimation(script.KnifeStab3)
	animStab[3].Stopped:connect(function()
		allowedToHit = false
		debounce = false
		tool.Handle.Transparency = 0
	end)
	
	-- Load anim throw
	animThrow = tool.Parent.Humanoid:LoadAnimation(script.KnifeThrow)
	--[[animThrow.KeyframeReached:connect(function(name)
		if name == "Peak" and tool.Parent.ClassName ~= "Backpack" and throwType == 1 then
			
			-- Pause the animation
			animThrow:AdjustSpeed(0)
			
		elseif name == "Throw" and tool.Parent.ClassName ~= "Backpack" then
			
			-- Set up the knife projectile
			local copy = tool.Handle:clone()
			copy.Name = "KnifeProjectile"
			copy.Transparency = 0
			copy.Anchored = true
			local scr = script.KnifeProjectileScript:clone()
			scr.Owner.Value = tool.Parent
			scr.TeamColor.Value = tool.TeamColor.Value
			local hitPos = nil
			if throwType == 0 then
				hitPos = script.ServerGetMouseHitPosition:InvokeClient(toolPlr)
			elseif throwType == 1 then
				hitPos = lastMouseHitPos
			end
			scr.Velocity.Value = (hitPos - copy.Position).Unit * script.KnifeThrowSpeed.Value
			scr.Effect.Value = tool.Effect.Value
			scr.RotateAxis.Value = tool.RotateAxis.Value
			scr.GripCFrame.Value = (tool.NormalGrip.Value - tool.NormalGrip.Value.p):inverse()
			scr.Parent = copy
			
			-- Place in workspace
			copy.Parent = workspace
			scr.Disabled = false
			
			-- Make normal knife invisible
			tool.Handle.Transparency = 1
			disableEffects()
			
			-- Activate cooldown
			throwCooldown = true
			spawn(function()
				wait(0.5)
				tool.Handle.Transparency = 0
				debounce = false
				wait(script.KnifeThrowCooldown.Value - 0.5)
				throwCooldown = false
			end)
			
		end
	end)
	animThrow.Stopped:connect(function()
		if tool.Parent.ClassName ~= "Backpack" and tool.Handle.Transparency >= 1 then
			tool.Handle.Transparency = 0
			--animDraw:Play()
			enableEffects()
			game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Draw)
		else
			tool.Handle.Transparency = 0
			enableEffects()
			debounce = false
		end
	end)]]
	
	-- Draw the knife
	debounce = false
	enableEffects()
	game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Draw)
	tool.Handle.Transparency = 0
	
	-- Make display knife invisible
	if tool.Parent:FindFirstChild("DisplayKnife") then
		tool.Parent.DisplayKnife.Transparency = 1
		for _, i in pairs(tool.Parent.DisplayKnife:GetChildren()) do
			if i.ClassName ~= "SpecialMesh" and i.ClassName ~= "Weld" then
				i.Enabled = false
			end
		end
	end
	
end)

tool.Unequipped:connect(function()
	
	-- Destroy animation tracks
	animThrow:Stop()
	animThrow:destroy()
	animDraw:Stop()
	animDraw:destroy()
	for i=1, 3 do
		animStab[i]:Stop()
		animStab[i]:destroy()
	end
	
	-- Make display knife visible
	local chr = tool.Parent
	if tool.Parent ~= nil and tool.Parent.ClassName == "Backpack" then
		chr = tool.Parent.Parent.Character
	end
	if chr ~= nil then
		if chr:FindFirstChild("DisplayKnife") then
			chr.DisplayKnife.Transparency = 0
			for _, i in pairs(chr.DisplayKnife:GetChildren()) do
				if i.ClassName ~= "SpecialMesh" and i.ClassName ~= "Weld" then
					i.Enabled = true
				end
			end
		end
	end
	
end)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.